pythonsystemdwatchdog

Systemd Daemon in Python with watchdog support


I want to write a daemon in python which gets started via systemd.

I want to use Type=notify, this way I don't have to do the double fork magic.

According to the docs:

The reference implementation for this notification is provided by libsystemd-daemon.so

... how to do this with Python?


Solution

  • Probably, you could use sdnotify python module which is a pure-python implementation of sd_notify protocol. Actually, the protocol is rather simple, so the module implementation is quite short.

    To use watchdog machinery you should add WatchdocSec=<smth> to the unit file, and then send WATCHDOG=1 messages on a regular basis from your service. Check Restart= option as well.