I have a simple systemd service unit to restart my python script on unconditional exits so defined Restart=always in the service definition. I just want to absolutely make sure even if the script hangs in some way, I can restart it by enabling the WatchdogSec= variable in the unit file.

My problem is the official docs for systemd's journal does not explain it clearly.

Quoting from the same page,


Configures the watchdog timeout for a service. The watchdog is activated when the start-up is completed. The service must call sd_notify(3) regularly with "WATCHDOG=1" (i.e. the "keep-alive ping").

The part that is unclear is, will the service itself take care of maintaining the pings with the watchdog service (or) the application it is running (in my case - Python script) needs to maintain the ping by updating the environment variable mentioned.

My simple service definition

Description=dev-Status: Computes RF device availability status


ExecStart=/usr/bin/python /opt/foobar/foobar.py


So to this service file if I just add the below line, would it restart my script automatically?

  • Check out the original description here and the sd_notify man page. – meuh Nov 29 '17 at 17:10
  • @meuh : Forgive my ignorance on the subject. Could you post an answer on what you are referring here? – Inian Nov 29 '17 at 17:56

To "pat" or ping the watchdog, you can use the python systemd package to send the notification:

from systemd.daemon import notify, Notification
  • It worked real fine! Appreciate it, but can you point me what are the differences between these two similar python modules, the one you shared for systemd and python-systemd? They seem to have similar APIs built-in – Inian Nov 30 '17 at 8:57
  • The mosquito version uses Cython to generate the binding, whereas the systemd version uses a CPython C module. – Silas Parker Nov 30 '17 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.