I want to create a system service from a Python program. The standard way up until recently seems to have been to make a daemon; however, I've read here that systemd
can make many daemons obsolete: the idea is that you can use the main process to run the system service and let systemd
do the rest.
So, assuming the "cool" thing to do these days is to use the main process, then what I can't get my head around is how to handle stopping and restarting of the service gracefully (i.e. via sysctl myscript restart
, etc.)
I know systemd
has an ExecStop
parameter which can run a command on exit, and I guess I could write a script which sets a flag in a file somewhere, and my Python program could then periodically poll this file and act accordingly. However, I imagine there is a more graceful way to do this.
So, is it possible to handle stop/restart events without a daemon when using systemd
?