A pure asynchronous Python implementation of systemd's service notification protocol (sd_notify)
Project description
systemd Service Notification
This is a Calian fork of Garrett's Asyncio version (https://github.com/seatsnob/sdnotify-asyncio) of the systemd sd_notify package written by bb4242 (Brett Bethke), available at https://github.com/bb4242/sdnotify
This is a pure Python implementation of the
systemd
sd_notify
protocol. This protocol can be used to inform systemd about service start-up
completion, watchdog events, and other service status changes. Thus, this
package can be used to write system services in Python that play nicely with
systemd. async-sdnotify is compatible with Python 3.
Normally the SystemdNotifier.notify method silently ignores exceptions (for example, if the
systemd notification socket is not available) to allow applications to
function on non-systemd based systems. However, setting debug=True will
cause this method to raise any exceptions generated to the caller, to
aid in debugging.
Installation
pip install async-sdnotify
Example Usage
This is an example of a simple Python service that informs systemd when its
startup sequence is complete. It also sends periodic status updates to systemd,
which can be viewed with systemctl status test.
test.py
import aiosdnotify
import asyncio
async def main():
print("Test starting up...")
# In a real service, this is where you'd do real startup tasks
# like opening listening sockets, connecting to a database, etc...
await asyncio.sleep(2)
print("Test startup finished")
# Inform systemd that we've finished our startup sequence...
async with aiosdnotify.SystemdNotifier() as n:
n.ready()
count = 1
while True:
print("Running... {}".format(count))
n.status("Count is {}".format(count))
count += 1
await asyncio.sleep(2)
test.service
[Unit]
Description=A test service written in Python
[Service]
# Note: setting PYTHONUNBUFFERED is necessary to see the output of this service in the journal
# See https://docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED
Environment=PYTHONUNBUFFERED=true
# Adjust this line to the correct path to test.py
ExecStart=/usr/bin/python /path/to/test.py
# Note that we use Type=notify here since test.py will send "READY=1"
# when it's finished starting up
Type=notify
[Install]
WantedBy=multi-user.target
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_sdnotify-0.1.0.post2.tar.gz.
File metadata
- Download URL: async_sdnotify-0.1.0.post2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.5 Linux/5.14.0-362.8.1.el9_3.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b81241d0b7ba3a01adef08110f9c6187e7caf0fd0cb9f9e6cfeae0f420341ce1
|
|
| MD5 |
69f7bbbf0a03db0f3e164b9fb26ca718
|
|
| BLAKE2b-256 |
75f609b1a075295e56526e3983f35d24c2e2712b6722cc547cb11e77d2bb826a
|
File details
Details for the file async_sdnotify-0.1.0.post2-py3-none-any.whl.
File metadata
- Download URL: async_sdnotify-0.1.0.post2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.12.5 Linux/5.14.0-362.8.1.el9_3.x86_64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0065d42932d1b02e87d72c50800220860969668a8fa39fecf82f769ffe32b4e5
|
|
| MD5 |
815dcf2f6c8972da1740d6bb10489bc5
|
|
| BLAKE2b-256 |
7dd564b64f93bc283fb37336befa2d695369fd8b03783f8db35f8df2febb8592
|