sdnotify-wrapper-py


Namesdnotify-wrapper-py JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryNotify readiness to systemd by writing to stdout in a service
upload_time2024-01-30 13:51:55
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT 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.
keywords systemd daemon s6 sd_notify
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sdnotify-wrapper-py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "systemd daemon s6 sd_notify",
    "author": "",
    "author_email": "Simon Holesch <simon@holesch.de>",
    "download_url": "https://files.pythonhosted.org/packages/7f/7d/446a180b5153dcad5b7c570153565b0b18dde31c2ec92887876da9841f88/sdnotify_wrapper_py-1.0.0.tar.gz",
    "platform": null,
    "description": "# sdnotify-wrapper-py\n\nThis project provides a command line tool `sdnotify-wrapper`, that can be used\nto send a readiness notification from a service to systemd, by simply writing a\nnewline to stdout. This can be an alternative to [`sd_notify(3)`] or\n[`systemd-notify(1)`], if you don't want your service to depend on systemd.\n\n[`sd_notify(3)`]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html\n[`systemd-notify(1)`]: https://www.freedesktop.org/software/systemd/man/latest/systemd-notify.html\n\n## Installation\n\nThere's a package published on PyPi, so it can be installed either with `pip`,\nor globally with `pipx`:\n\n```\n$ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install sdnotify-wrapper-py\n```\n\n## Usage\n\nIn your service write one line to stdout whenever the service is ready (make\nsure to write logs to stderr instead). For example in Python (characters other\nthan a newline are ignored):\n\n```python\nprint(\"ready\", flush=True)\n```\n\nOr in C:\n\n```c\nwrite(1, \"\\n\", 1)\n```\n\nThen create a systemd service file with `Type=notify`, e.g. if your service\nwould be started with `my-service --foo bar`:\n\n```ini\n[Unit]\nDescription=My Service\n\n[Service]\nType=notify\nNotifyAccess=all\nExecStart=/usr/local/bin/sdnotify-wrapper my-service --foo bar\n\n[Install]\nWantedBy=multi-user.target\n```\n\n`sdnotify-wrapper` will then connect to the stdout of your service, notify\nsystemd when it reads a newline and exit.\n\n## Why Python?\n\n`sdnotify-wrapper` is a tool originally written by Laurent Bercot:\n[`sdnotify-wrapper.c`][1]. Unfortunately this tool is not packaged for any of\nthe major Linux distributions, so it's not a great user experience if your\nservice requires this mechanism.\n\nI chose to reimplement this tool in Python mainly, because it's easier to\ninstall it with a Python package manager. In doing this, I hope this readiness\nnotification mechanism will be adopted by more projects and the original tool\nwill be packaged by more distributions.\n\n[1]: https://www.skarnet.org/software/misc/sdnotify-wrapper.c\n",
    "bugtrack_url": null,
    "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.",
    "summary": "Notify readiness to systemd by writing to stdout in a service",
    "version": "1.0.0",
    "project_urls": {
        "Issues": "https://github.com/holesch/sdnotify-wrapper-py/issues",
        "Source": "https://github.com/holesch/sdnotify-wrapper-py"
    },
    "split_keywords": [
        "systemd",
        "daemon",
        "s6",
        "sd_notify"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee0d59047523e5e49017e5fbb197435f347715d2023fc331c5ab99f19802dc35",
                "md5": "f7cf1535a04cdf4651c3d86d30176f32",
                "sha256": "538b83f4ae6a6ff3a0ffdcf0245ca5828de17e4a1630db069a1f8531c5a92269"
            },
            "downloads": -1,
            "filename": "sdnotify_wrapper_py-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f7cf1535a04cdf4651c3d86d30176f32",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5307,
            "upload_time": "2024-01-30T13:51:54",
            "upload_time_iso_8601": "2024-01-30T13:51:54.476557Z",
            "url": "https://files.pythonhosted.org/packages/ee/0d/59047523e5e49017e5fbb197435f347715d2023fc331c5ab99f19802dc35/sdnotify_wrapper_py-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f7d446a180b5153dcad5b7c570153565b0b18dde31c2ec92887876da9841f88",
                "md5": "ad7584c5ca9bd8f3575d28012f615a46",
                "sha256": "3f5e0c3de77128ee639f133b6df8a776899f7fe3f5fb4ed8e566ae28aca87003"
            },
            "downloads": -1,
            "filename": "sdnotify_wrapper_py-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ad7584c5ca9bd8f3575d28012f615a46",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5587,
            "upload_time": "2024-01-30T13:51:55",
            "upload_time_iso_8601": "2024-01-30T13:51:55.917217Z",
            "url": "https://files.pythonhosted.org/packages/7f/7d/446a180b5153dcad5b7c570153565b0b18dde31c2ec92887876da9841f88/sdnotify_wrapper_py-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-30 13:51:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "holesch",
    "github_project": "sdnotify-wrapper-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sdnotify-wrapper-py"
}
        
Elapsed time: 0.30940s