Lightweight Python module wrapper for systemctl
A lightweight Python module to interact with systemd
services via systemctl
, designed for use in Python-based service managers, admin tools, and dashboards.
systemctl
outputpip install git+https://github.com/NadimGhaznavi/db4esystemd.git
Or clone locally:
git clone https://github.com/NadimGhaznavi/db4esystemd.git
cd db4e-systemd
from Db4eSystemd.Db4eSystemd import Db4eSystemd
svc = Db4eSystemd('db4e')
if not svc.installed():
print("Service not installed")
elif not svc.active():
print("Service is stopped. Starting...")
svc.start()
else:
print(f"Service is running with PID {svc.pid()}")
svc = Db4eSystemd('myservice')
svc.start() # Start service
svc.stop() # Stop service
svc.restart() # Restart service
svc.status() # Refresh status
svc.active() # True/False
svc.enabled() # True/False
svc.installed() # True/False
svc.pid() # Integer PID or None
svc.stdout() # Raw systemctl stdout
svc.stderr() # Raw systemctl stderr
GPL v3 - See LICENSE.txt
Created and maintained by Nadim-Daniel Ghaznavi. Part of the db4e project.