I've been using the service unit bellow to start a couple of process that happens to have a high CPU and disk bandwidth usage when running.
Since the processes I want to limit don't have a way to indicate how much resources they should take, I've been using CGroups to control how much they should take of the available resources.
The problem is that if CGroups fails the systems becomes unresponsive and needs to be restarted, so I'd like to have a way to stop the processes in that case.
The service unit for CGroups should restart the service on failure, but for some reason it didn't, maybe because the system became unresponsive.
I don't have the logs either, because the system was shutdown due to high resources usage, and I don't have access to that information until an admin remove the suspension.
Service unit to be limited
[Unit]
Description=HIGH RESOURCES USAGE daemon
After=cgroups.service network.target
[Service]
User=myuser
Group=myuser
ExecStart=/usr/bin/xxxxxxxx
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/xxxxxxxx
WorkingDirectory=/home/myuser
[Install]
WantedBy=multi-user.target
CGroups service unit
[Unit]
Description=Load cgroup configs
After=remote-fs.target
[Service]
Type=forking
ExecStartPre=/bin/echo "Processing /etc/cgconfig.conf..."
ExecStartPre=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf
ExecStartPre=/bin/echo "Processing /etc/cgrules.conf..."
ExecStart=/usr/sbin/cgrulesengd --logfile=/var/log/cgrulesengd.log
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
cgconfig.conf
group app_limit {
cpu {
cpu.cfs_quota_us = 200000
cpu.cfs_period_us = 1000000
}
blkio {
blkio.throttle.read_iops_device = "253:0 35";
blkio.throttle.write_iops_device = "253:0 35";
blkio.throttle.write_bps_device = "253:0 262144000";
}
}
cgrules.conf
myuser cpu,blkio app_limit/