systemd-pydantic
Pydantic models for systemd service and timer units.
Overview
systemd-pydantic provides typed, YAML-friendly models, lifecycle clients, and convenience commands for systemd. Its layers mirror supervisor-pydantic:
ServiceConfiguration:[Service]settings, analogous toProgramConfigurationServiceUnitConfigurationandTimerUnitConfiguration: individual unit filesSystemdConfiguration: named service and timer collections, file persistence, Hydra loading, and basic lifecycle methodsSystemdConvenienceConfiguration: defaults and persisted JSON used by external tools such as AirflowSystemdClient: typedsystemctloperations andUnitInfostate_systemd_convenience: lifecycle CLI for local or SSH-driven orchestration
Timer support lives in this package because timers share systemd's common [Unit] and [Install] sections and normally activate a matching service unit.
Configuration
from systemd_pydantic import ServiceConfiguration, ServiceUnitConfiguration, SystemdConfiguration
config = SystemdConfiguration(
service={
"long-running-job": ServiceUnitConfiguration(
unit={"description": "Long-running Airflow job"},
service=ServiceConfiguration(
type="exec",
exec_start="/opt/jobs/run",
restart="on-failure",
restart_sec="5s",
environment={"MODE": "production"},
),
)
},
scope="user",
)
config.write()
Dictionary input works identically, making the configuration suitable for YAML and Hydra:
# @package _global_
service:
long-running-job:
unit:
description: Long-running Airflow job
service:
type: exec
exec_start: /opt/jobs/run
restart: on-failure
restart_sec: 5s
environment:
MODE: production
scope: user
Timer values accept systemd time strings or Python timedelta values. Repeated calendar and monotonic triggers render as repeated directives, preserving systemd semantics.
scope="system" writes to /etc/systemd/system and calls systemctl. scope="user" writes to ~/.config/systemd/user and calls systemctl --user. The executing user must have permission to write the selected unit directory and control its systemd manager.
Lifecycle client
from systemd_pydantic import SystemdClient
client = SystemdClient(config)
client.daemon_reload()
client.start_services()
for unit in client.get_all_service_info().values():
print(unit.name, unit.active_state, unit.result)
SystemdClient also supports stopping, restarting, killing, enabling, and disabling units. A custom CommandRunner can be injected for tests or remote execution.
Convenience CLI
SystemdConvenienceConfiguration persists its JSON representation alongside generated units. The _systemd_convenience CLI consumes that file and provides commands aligned with supervisor-pydantic:
configure-systemd
start-services
check-services
restart-services
stop-services
unconfigure-systemd
Systemd itself is already running, so there are intentionally no start-systemd or stop-systemd daemon commands.
[!NOTE] This library was generated using copier from the Base Python Project Template repository.
Metadata
Release files for systemd-pydantic 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| systemd_pydantic-0.1.0.tar.gz | 18.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| systemd_pydantic-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.3 kB
Release files / systemd_pydantic-0.1.0.tar.gz
| Download URL | systemd_pydantic-0.1.0.tar.gz |
|---|---|
| Size | 18.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0dfdb76ae6491a8f8b1fb1d55f117fd083617e2328b915d784801a2719289b4
|
|
BLAKE2b-256 checksum How to use checksums |
c10efd41a866d169d393ae9e2b790794e3983348ffac99805dfbd177cdca35aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / systemd_pydantic-0.1.0-py3-none-any.whl
| Download URL | systemd_pydantic-0.1.0-py3-none-any.whl |
|---|---|
| Size | 23.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a736a11807ee178dbc56b498474ffd36cdf6caeae5f904b5b25fbe0ab15a926f
|
|
BLAKE2b-256 checksum How to use checksums |
980c6dfa1a0a6a287cc5796f572ca276feb8de8e3ab54b51e24caeb5826a3d2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|