====== daemon ======
===== systemd =====
[[https://stackoverflow.com/questions/13069634/python-daemon-and-systemd-service|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 [[https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type=|Type=]]).
Hints:
* To force systemd to wait for full process startup, use [[https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#|sd_notify(3)]] and set unit ''type=notify''
* ''Notify'' also ensure that ''ExecStartPost'' will be executed after notify received.
* To prevent output buffering and correct journal logging set ''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