Skip to main content

sdnotify-wrapper-py

This project provides a command line tool sdnotify-wrapper, that can be used to send a readiness notification from a service to systemd, by simply writing a newline to stdout. This can be an alternative to sd_notify(3) or systemd-notify(1), if you don't want your service to depend on systemd.

Installation

There's a package published on PyPi, so it can be installed either with pip, or globally with pipx:

$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install sdnotify-wrapper-py

Usage

In your service write one line to stdout whenever the service is ready (make sure to write logs to stderr instead). For example in Python (characters other than a newline are ignored):

print("ready", flush=True)

Or in C:

write(1, "\n", 1)

Then create a systemd service file with Type=notify, e.g. if your service would be started with my-service --foo bar:

[Unit]
Description=My Service

[Service]
Type=notify
NotifyAccess=all
ExecStart=/usr/local/bin/sdnotify-wrapper my-service --foo bar

[Install]
WantedBy=multi-user.target

sdnotify-wrapper will then connect to the stdout of your service, notify systemd when it reads a newline and exit.

Why Python?

sdnotify-wrapper is a tool originally written by Laurent Bercot: sdnotify-wrapper.c. Unfortunately this tool is not packaged for any of the major Linux distributions, so it's not a great user experience if your service requires this mechanism.

I chose to reimplement this tool in Python mainly, because it's easier to install it with a Python package manager. In doing this, I hope this readiness notification mechanism will be adopted by more projects and the original tool will be packaged by more distributions.

Metadata

Release files for sdnotify-wrapper-py 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sdnotify-wrapper-py 1.0.0
File Size Uploaded
sdnotify_wrapper_py-1.0.0.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sdnotify-wrapper-py 1.0.0
File Interpreter ABI Platform
sdnotify_wrapper_py-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / sdnotify_wrapper_py-1.0.0.tar.gz

Download URL sdnotify_wrapper_py-1.0.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3f5e0c3de77128ee639f133b6df8a776899f7fe3f5fb4ed8e566ae28aca87003
BLAKE2b-256 checksum
How to use checksums
7f7d446a180b5153dcad5b7c570153565b0b18dde31c2ec92887876da9841f88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / sdnotify_wrapper_py-1.0.0-py3-none-any.whl

Download URL sdnotify_wrapper_py-1.0.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
538b83f4ae6a6ff3a0ffdcf0245ca5828de17e4a1630db069a1f8531c5a92269
BLAKE2b-256 checksum
How to use checksums
ee0d59047523e5e49017e5fbb197435f347715d2023fc331c5ab99f19802dc35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page