Metadata-Version: 2.1
Name: sdnotify-wrapper-py
Version: 1.0.0
Summary: Notify readiness to systemd by writing to stdout in a service
Keywords: systemd daemon s6 sd_notify
Author-Email: Simon Holesch <simon@holesch.de>
License: MIT License
        
        Copyright (c) 2024-present Simon Holesch <simon@holesch.de>
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Boot :: Init
Classifier: Topic :: System :: Systems Administration
Project-URL: Issues, https://github.com/holesch/sdnotify-wrapper-py/issues
Project-URL: Source, https://github.com/holesch/sdnotify-wrapper-py
Requires-Python: >=3.7
Provides-Extra: test
Requires-Dist: black; extra == "test"
Requires-Dist: codespell; extra == "test"
Requires-Dist: isort; extra == "test"
Requires-Dist: pylint; extra == "test"
Description-Content-Type: text/markdown

# 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.

[`sd_notify(3)`]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html
[`systemd-notify(1)`]: https://www.freedesktop.org/software/systemd/man/latest/systemd-notify.html

## 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):

```python
print("ready", flush=True)
```

Or in C:

```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`:

```ini
[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`][1]. 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.

[1]: https://www.skarnet.org/software/misc/sdnotify-wrapper.c
