Expand description
unitbus is a Rust SDK for Linux systemd: control units/jobs via the system D-Bus (systemctl-like), run one-shot transient tasks, and query journald logs (default: pure Rust backend).
It is designed as a control-plane foundation for traditional deployments (non-Kubernetes) and CD/agent tooling.
Runtime is Linux-only (systemd + system bus required). The public API is designed to compile on
other platforms but will return Error::BackendUnavailable where appropriate.
§Quick start
use unitbus::{UnitBus, UnitStartMode};
async fn restart_nginx() -> Result<(), unitbus::Error> {
let bus = UnitBus::connect_system().await?;
let job = bus.units().restart("nginx", UnitStartMode::Replace).await?;
let outcome = job.wait(std::time::Duration::from_secs(30)).await?;
println!("{outcome:?}");
Ok(())
}§Unit name rules
- You can pass either a full unit name (e.g.
"nginx.service") or a shorthand (e.g."nginx"). - Shorthand names are canonicalized to
"<name>.service". - Names containing path separators or control characters are rejected as
Error::InvalidInput.
§Journald limits
The journald backend enforces bounded results:
limit(default: 200)max_bytes(default: 1 MiB)max_message_bytes(default: 16 KiB)
Default backend: pure Rust journal reader (feature=journal-sdjournal).
Alternative backend: journalctl --output=json (feature=journal-cli).
When limits are exceeded, the returned JournalResult.truncated is set to true.
Structs§
- Capabilities
- Runtime capabilities derived from conservative probing.
- Diagnosis
- Diagnosis
Options - Options for
diagnose_unit_failure. - JobHandle
- Handle for a systemd job.
- Journal
- Journal
Entry - One log entry from journald.
- Journal
Filter - Query filter for journald.
- Journal
Result - Journal
Stats - Manager
- systemd
ManagerAPIs. - Manager
Info - A small snapshot of
org.freedesktop.systemd1.Managerglobal information. - Properties
- A
GetAllproperty bag (values are stored internally as D-Bus variants). - Service
Unit Spec - Specification for generating a systemd service unit file.
- UnitBus
- Primary entrypoint for interacting with systemd and journald.
- Unit
BusOptions - Configuration options for
UnitBus. - Unit
List Entry - A single row returned by
org.freedesktop.systemd1.Manager.ListUnits*. - Unit
Status - Snapshot of relevant systemd unit/service properties.
- Units
- Unit/job control APIs.
Enums§
- Active
State - systemd
Unit.ActiveState. - Error
- Error returned by unitbus APIs.
- Failure
Hint - A best-effort classification of why a job failed.
- JobOutcome
- Normalized outcome for a job wait.
- Load
State - systemd
Unit.LoadState. - Parse
Error Mode - How to handle malformed journal entries from the configured backend.
- Service
Type - systemd service
Type=.... - Unit
Start Mode - systemd
StartUnit/StopUnitmode.
Type Aliases§
- Journal
Cursor - Result
- Crate-wide result type.