sd_notify and sd_watchdog_enabled functionality for writing Python daemons under systemd
Project description
systemd_watchdog
sd_notify(3) and sd_watchdog_enabled(3) client functionality implemented in Python 3 for writing Python daemons
Install
$ pip install systemd-watchdog
or
$ git clone ...
$ make install
Usage
import systemd_watchdog
wd = systemd_watchdog.watchdog()
if not wd.enabled():
# Then it's probably not running is systemd with watchdog enabled
raise Exception("Watchdog not enabled")
# Report a status message
wd.status("Starting my service...")
time.sleep(3)
# Report that the program init is complete
wd.ready()
wd.status("Waiting for web requests...")
wd.notify()
time.sleep(3)
# Compute time between notifications
timeout_half_sec = int(float(wd.timeout) / 2e6) # Convert us->s and half that
time.sleep(timeout_half_sec)
wd.notify()
# Report an error to the service manager
wd.notify_error("An irrecoverable error occured!")
# The service manager will probably kill the program here
time.sleep(3)
Public Reference
<class 'systemd_watchdog.watchdog'>
is_enabled
Boolean property stating whether watchdog capability is enabled.
timeout
Property reporting the number of microseconds (int) before process will be killed.
It is recommended that you call notify()
once roughly half of this interval has passed (see notify_due
).
timeout_td
Property that is the same as timeout
but presented as datetime.timedelta
for easier manipulation.
notify_due
Boolean property indicating more than half of the watchdog interval has passed since last update.
notify()
Report a healthy service state. Other calls, e.g. status()
do not reset the watchdog.
notify_error(msg=None)
Report an error to the watchdog manager. This program will likely be killed upon receipt.
If msg
is provided, it will be reported as a status message prior to the error.
ready()
Report ready service state, i.e. completed initialisation (only needed with Type=notify
)
status(msg)
Send a service status message.
History
Aaron D. Marasco May 2020
- Forked from the sd-notify project https://github.com/stigok/sd-notify
- Additional contributors can be found in GitHub repository history
License
See LICENSE
file
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for systemd_watchdog-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a630e17219218b727249c44a0110e8e48415acb9216d49f77bfc49b19e1e5df5 |
|
MD5 | 17cb62c0682aac21823a3c18c958a3e2 |
|
BLAKE2b-256 | d934bd9af3ddff7956c898a8d544b6a28f406730a923d92cffa6825171203304 |