Crate unitbus

Crate unitbus 

Source
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
DiagnosisOptions
Options for diagnose_unit_failure.
JobHandle
Handle for a systemd job.
Journal
JournalEntry
One log entry from journald.
JournalFilter
Query filter for journald.
JournalResult
JournalStats
Manager
systemd Manager APIs.
ManagerInfo
A small snapshot of org.freedesktop.systemd1.Manager global information.
Properties
A GetAll property bag (values are stored internally as D-Bus variants).
ServiceUnitSpec
Specification for generating a systemd service unit file.
UnitBus
Primary entrypoint for interacting with systemd and journald.
UnitBusOptions
Configuration options for UnitBus.
UnitListEntry
A single row returned by org.freedesktop.systemd1.Manager.ListUnits*.
UnitStatus
Snapshot of relevant systemd unit/service properties.
Units
Unit/job control APIs.

Enums§

ActiveState
systemd Unit.ActiveState.
Error
Error returned by unitbus APIs.
FailureHint
A best-effort classification of why a job failed.
JobOutcome
Normalized outcome for a job wait.
LoadState
systemd Unit.LoadState.
ParseErrorMode
How to handle malformed journal entries from the configured backend.
ServiceType
systemd service Type=....
UnitStartMode
systemd StartUnit/StopUnit mode.

Type Aliases§

JournalCursor
Result
Crate-wide result type.