Originally posted by aht0
View Post
The cause of why systemd does timeouts on shutdown and service stop/restart is that it detects due to cgroups that processes are still running. So systemd runs the stop command on a service on shutdown then checks if all processes owning to that service have in fact stopped if not it waits after X amount time it brute force kills it.
Lets look how sysvinit and the like handle it.
On shutdown.
1) sends all the services running stop in order of the kill number.
2) After all services have been sent stop run a killall to clean house.
Please note if the last process to get a stop order next operation is the killall by sysvinit there basically no delay between killall clean up coming. Systemd changes this to a predictable delay. Yes this is one of the cause how sysvinit at times screwed over databases delayed by IO for some reason to be killed before final writes were done due to no delay.
Next is kind of worse.
You attempt a sysvinit service restart and the service fails to restart. There is a leaked process holding something the service needs to restart. Yes systemd by systemctl doing a restart on something like this you would see a timeout as well and the service be successfully restarted.
Basically systemd using normal sysvinit scripts if you are seeing timeouts you sysvinit scripts have a defect that needs fixing.
Systemd turns what was a silent failure on shutdown with sysvinit into a loud message making failure with those timeout messages. That failure does not just effect the services with that problem at shutdown it also effect those services when ever you wish to restart them.
This is some of the problem. People complain about the shutdown timeout issue of systemd without think maybe systemd is right here might pay to research why. Systemd shutdown timeouts is point you to broken init scripts.
For the complete time I run systemd I have not had a single shutdown timeout but my init scripts had been audited well before using PID namespaces for process leakage. Process leakage has been insanely common defect causing random issues well before systemd existance.
Systemd timeout messages on shutdown are just symptom of non systemd defects. Yes defects that sysvinit would silent hide until the day it catches you where you end up reboot a server instead of just restarting a service because a service will not restart.
Yes these messes is why I say systemd is the init system we had to have. One of the results of systemd was a lot of sysvinit scripts in fact got fixed or deprecated with a systemd unit file that is also fixed.
Comment