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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file systemd_pydantic-0.1.0.tar.gz.
File metadata
- Download URL: systemd_pydantic-0.1.0.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0dfdb76ae6491a8f8b1fb1d55f117fd083617e2328b915d784801a2719289b4
|
|
| MD5 |
558965e16c396dc558a340ecda855ea3
|
|
| BLAKE2b-256 |
c10efd41a866d169d393ae9e2b790794e3983348ffac99805dfbd177cdca35aa
|
File details
Details for the file systemd_pydantic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: systemd_pydantic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a736a11807ee178dbc56b498474ffd36cdf6caeae5f904b5b25fbe0ab15a926f
|
|
| MD5 |
ea46f322b77e92c67393ccdb5e5c7bdf
|
|
| BLAKE2b-256 |
980c6dfa1a0a6a287cc5796f572ca276feb8de8e3ab54b51e24caeb5826a3d2e
|