在systemd v250环境中,当我重新启动服务时,它cgroup.subtree_control
被重置。
如果我修改 的值cgroup.subtree_control
,那么当我重新启动服务时,systemd 将尝试覆盖 的值cgroup.subtree_control
。例如,如果我cpu
向 subtree_control 添加一个控制器,则当服务重新启动时,systemd 会将其从 subtree_control 中删除。如果我此时创建了一个子目录,并且重启时子组中还有进程,那么启动就会失败。错误如下:
Control process exited, code=exited, status=219/CGROUP
...
Unit process 543222 (xxx) remains running after unit stoped.
....
重写 subtree_control 时这似乎失败了。
我想cgroup.subtree_control
在启用委托时自行管理。
我希望 systemd 不要修改它,不要cgroup.subtree_control
在服务重新启动时重置委托服务。
相关文件
单元文件:
[Unit]
Description=DelegateTest
[Service]
Type=simple
TimeoutSec=60s
KillMode=process
ExecStartPre=/bin/bash /test/start_pre.sh
ExecStart=/bin/bash /test/loader.sh
ExecStop=/bin/kill $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
Delegate=yes
/test/start_pre.sh:
echo "start_pre"
/测试/loader.sh
echo "executing"
CGROUP=$(cat /proc/$$/cgroup)
CGROUP_PATH=/sys/fs/cgroup${CGROUP#*::}
if [[ ! -d ${CGROUP_PATH}/job ]]; then
mkdir ${CGROUP_PATH}/job
fi
echo $$ > ${CGROUP_PATH}/job/cgroup.procs
echo "+cpu" > ${CGROUP_PATH}/cgroup.subtree_control
ping 127.0.0.1 > /dev/null
重现此问题的步骤
- systemctl 启动 DelegateTest.service
- systemctl status DelegateTest.service
Loaded: loaded (/usr/lib/systemd/system/DelegateTest.service; static)
Active: active (running) since Thu 2022-07-21 09:58:31 CST; 1s ago
Process: 541635 ExecStartPre=/bin/bash /test/start_pre.sh (code=exited, status=0/SUCCESS)
Main PID: 541636 (bash)
Tasks: 2 (limit: 23196)
Memory: 660.0K
CPU: 11ms
CGroup: /system.slice/DelegateTest.service
└─job
├─541636 /bin/bash /test/loader.sh
└─541639 ping 127.0.0.1
- systemctl stop DelegateTest.service
- systemctl status DelegateTest.service
Loaded: loaded (/usr/lib/systemd/system/DelegateTest.service; static)
Active: inactive (dead) since Thu 2022-07-21 09:58:36 CST; 981ms ago
Process: 541635 ExecStartPre=/bin/bash /test/start_pre.sh (code=exited, status=0/SUCCESS)
Process: 541636 ExecStart=/bin/bash /test/loader.sh (code=killed, signal=TERM)
Process: 541644 ExecStop=/bin/kill $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 541636 (code=killed, signal=TERM)
Tasks: 1 (limit: 23196)
Memory: 300.0K
CPU: 13ms
CGroup: /system.slice/DelegateTest.service
└─job
└─541639 ping 127.0.0.1
- systemctl 启动 DelegateTest.service
Job for DelegateTest.service failed because the control process exited with error code.
See "systemctl status DelegateTest.service" and "journalctl -xeu DelegateTest.service" for details.
- systemctl status DelegateTest.service
× DelegateTest.service - DelegateTest
Loaded: loaded (/usr/lib/systemd/system/DelegateTest.service; static)
Active: failed (Result: exit-code) since Thu 2022-07-21 09:58:53 CST; 1s ago
Process: 541649 ExecStartPre=/bin/bash /test/start_pre.sh (code=exited, status=219/CGROUP)
Tasks: 1 (limit: 23196)
Memory: 300.0K
CPU: 84us
CGroup: /system.slice/DelegateTest.service
└─job
└─541639 ping 127.0.0.1
相关问题:
https://github.com/systemd/systemd/issues/24064 https://github.com/systemd/systemd/issues/20026 https://github.com/systemd/systemd/issues/18293 https://github.com/systemd/systemd/pull/9119 https://github.com/systemd/systemd/issues/8645 https://github.com/systemd/systemd/issues/18104