13 ms·
My foo-daemon needs some arguments and several steps to shutdown while saving its work. Like maybe kill -HUP, wait 10 seconds and then kill -9. Any suggestions
by cat_plus_plus 4y ago
My foo-daemon needs some arguments and several steps to shutdown while saving its work. Like maybe kill -HUP, wait 10 seconds and then kill -9. Any suggestions that would be obvious to me without always having you for one-on-one consultation? Rare cases where saving work is not complete after 10 seconds are acceptable for my use case.
- raggi 4y agoSure, here's the doc this is taken from: https://www.freedesktop.org/software/systemd/man/systemd.service.html#id-1.10.2 https://www.freedesktop.org/software/systemd/man/systemd.ser... You can find this doc by typing "systemd.service" into your favorite search engine. The title I link to is the simple case example, which explains just below the content sample that it has pretty much the behavior you want: Since no ExecStop= was specified, systemd will send SIGTERM to all processes started from this service, and after a timeout also SIGKILL. This behavior can be modified, see systemd.kill(5) for details. Per this, you can either implement SIGTERM rather than SIGHUP, or you can change the stop signal. It already has a generous shutdown timeout (on one of my systems where I have a similarly simple unit, it's defaulted to 1m30s). You can change the timeout by setting https://www.freedesktop.org/software/systemd/man/systemd.service.html#TimeoutStopSec= https://www.freedesktop.org/software/systemd/man/systemd.ser... The docs are pretty good, and worth a scan. Edit: I forgot about the arguments, you can just add them to the ExecStart= line (doc: https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart= https://www.freedesktop.org/software/systemd/man/systemd.ser...).
- andrewstuart 4y agoThat's bread and butter work for systemd - exactly what it is designed to handle.
- ilyt 4y agoIf your daemon needs kill -9 you fucked up but even then you can just set "stop timeout" and your demon will get the termination signal, and kill after that interval. More crude option is putting all of the custom stop behaviour in ExecStop script