TransWikia.com

"systemctl set-property user-1009.slice CPUQuota=50%" - Failed to set unit properties on user-1009.slice: Unit user-1009.slice is not loaded

Unix & Linux Asked by die4ever2005 on November 16, 2021

I’m trying to set per-user limits on processes, most of them are run with sudo –user. Why do user-1001 and user-1008 on my system have the slice files, but I can’t get it on 1009?

# systemctl set-property user-1009.slice CPUQuota=50%
Failed to set unit properties on user-1009.slice: Unit user-1009.slice is not loaded.

# systemctl status user-1009.slice
● user-1009.slice
   Loaded: loaded
   Active: inactive (dead)

I tried manually creating the file

# touch /etc/systemd/system/user-1009.slice

# systemctl status user-1009.slice
● user-1009.slice
   Loaded: masked (/etc/systemd/system/user-1009.slice; masked; vendor preset: disabled)
   Active: inactive (dead)

# systemctl set-property user-1009.slice CPUQuota=50%
Failed to set unit properties on user-1009.slice: Unit user-1009.slice is not loaded.

Also this doesn’t make sense to me, the testprocess (PID 26668) shows in ps -U 1009, but it’s running under the slice for user-1008 (because user-1008 used sudo to run it?)

# ps -U 1009 ; systemctl status user-1008.slice
  PID TTY          TIME CMD
15727 pts/1    00:00:00 bash
26668 ?        00:00:00 testprocess
● user-1008.slice - User Slice of testuser
   Loaded: loaded (/run/systemd/system/user-1008.slice; static; vendor preset: disabled)
  Drop-In: /run/systemd/system/user-1008.slice.d
           └─50-After-systemd-logindx2eservice.conf, 50-After-systemd-user-sessionsx2eservice.conf, 50-Description.conf, 50-TasksMax.conf
   Active: active since Thu 2018-08-30 19:35:01 EDT; 2 days ago
   CGroup: /user.slice/user-1008.slice
           └─session-1801668.scope
             └─26668 ./testprocess

Searching around, all I could find is people saying to login as the user to fix this, but obviously the user has processes open. And I tried using su – user1009 in another terminal, but that didn’t seem to help

2 Answers

I'm trying to set per-user limits on processes, most of them are run with sudo --user.

Why do user-1001 and user-1008 on my system have the slice files units, but I can't get it on 1009?

If you aren't running the UID 1009 processes right now, then systemd (or technically logind) will not start the slice for that UID.

Also, even if you successfully apply any settings while the processes are running, they will be lost if the processes all stop running. Because the slice unit will be stopped again. Sometimes this might be what you want, but it sounds to me like it could be very confusing.

It would make more sense to add your desired settings in a drop-in config file, e.g. /etc/systemd/system/user-1009.slice.d/cpuquota.conf.

Use systemd-analyze verify user-1009.slice to check the config file, and systemctl daemon-reload to load it. I think the updated config will not take effect until after the slice unit has been stopped. You can also restart the slice unit manually, but this will kill any processes running inside it.


If you don't have user-1009.slice when your processes are running, it's because the processes of that user are not really being run inside pam_systemd. This might be because they're not started using PAM. Also it might be because the PAM "service" is not configured to use pam_systemd.

sudo/su on Linux should use PAM. And in the configurations I've seen on RedHat and Debian based OS's, it uses pam_systemd. But, there is a third case where pam_systemd would not take effect: if you are running the command inside an existing user session. See https://github.com/systemd/systemd/issues/7451

That last point explains some confusing behaviour of su, i.e. why you didn't see any processes in user-1009.slice when you manually ran su - user-1009.

Answered by sourcejedi on November 16, 2021

Just in case someone else needs a solution, instead of using just sudo, sudo systemd-run worked for me

$ sudo systemd-run --uid=1009 --slice=user-1009 sleep 10

# ps -U 1009 ; systemctl status user-1009.slice

PID TTY TIME CMD

20199 ? 00:00:00 sleep

● user-1009.slice

Loaded: loaded

Active: active since Sun 2018-09-02 01:46:57 EDT; 2s ago

CGroup: /user.slice/user-1009.slice

      └─run-20198.service

        └─20199 /bin/sleep 10

https://www.reddit.com/r/linuxquestions/comments/9c9dka/issue_with_systemctl_setproperty_user1009slice

Answered by die4ever2005 on November 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP