Python daemon and systemd service
When using systemd, it is no need to implement daemon in main process.
Systemd simply works with foreground services (default service type=simple
. See Type=).
Hints:
type=notify
Notify
also ensure that ExecStartPost
will be executed after notify received.PYTHONUNBUFFERED=1
environment or flush stdout more often sys.stdout.flush()
Example:
import systemd.daemon # long startup # ... # long startup done systemd.daemon.notify('READY=1') # start servicing
[Service] Type=notify ExecStart=/usr/bin/my_service ExecStartPost=/usr/bin/my_service_client Environment=PYTHONUNBUFFERED=1