Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
MANIFEST
.Python
env/
build/
develop-eggs/
dist/
Expand All @@ -21,9 +16,50 @@ lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

*~
# pytype static type analyzer
.pytype/
File renamed without changes.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#License
include LICENSE.txt
include LICENSE
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# systemd Service Notification

> [!NOTE]
> This is a fork of https://github.com/bb4242/sdnotify/ keeping the project
> alive without major changes.

This is a pure Python implementation of the
[`systemd`](http://www.freedesktop.org/wiki/Software/systemd/)
[`sd_notify`](http://www.freedesktop.org/software/systemd/man/sd_notify.html)
Expand All @@ -14,10 +18,6 @@ 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 sdnotify`

# Example Usage

This is an example of a simple Python service that informs `systemd` when its
Expand All @@ -26,7 +26,7 @@ which can be viewed with `systemctl status test`.

## `test.py`
```python
import sdnotify
from sdnotify import sd_notify
import time

print("Test starting up...")
Expand All @@ -36,30 +36,30 @@ time.sleep(10)
print("Test startup finished")

# Inform systemd that we've finished our startup sequence...
n = sdnotify.SystemdNotifier()
n.notify("READY=1")
sd_notify.ready()

count = 1
while True:
print("Running... {}".format(count))
n.notify("STATUS=Count is {}".format(count))
sd_notify.status("Count is {}".format(count))
count += 1
time.sleep(2)
```

## `test.service`
```properties
[Unit]
Description=A test service written in Python

[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

[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

# 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
# Note that we use Type=notify here since test.py will send "READY=1"
# when it's finished starting up
Type=notify
```
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[build-system]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"

[project]
name = "sdnotify"
version = "0.4.0-rc"

description = "A pure Python implementation of systemd's service notification protocol (sd_notify)"
readme = "README.md"
license = {file = "LICENSE"}
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX :: Linux",
"Topic :: Software Development :: Libraries :: Python Modules",
]

Loading