6

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

I wan 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?

guettli
  • 23,964
  • 63
  • 293
  • 556
  • Possibly related: https://www.freedesktop.org/software/systemd/python-systemd/daemon.html http://stackoverflow.com/questions/13069634/python-daemon-and-systemd-service – Robᵩ Apr 27 '16 at 15:22
  • @Robᵩ The question you mention does not solve my question, since my question is about a daemon with **watchdog** support. If my daemon hangs in an endless loop, I want systemd to know that the service does not respond. Without watchdog systemd things my service is alive as long as the process runs. – guettli May 02 '16 at 11:38

2 Answers2

9

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.

user3159253
  • 15,770
  • 3
  • 26
  • 46
-1

use the package
https://pypi.org/project/systemd-python/
it is the offical systemd devs and maintained.

qrtLs
  • 1,686
  • 20
  • 42