Unitctl (unitctl v0.1.0)

Copy Markdown View Source

Docker-like process controls backed by pure systemd primitives.

unitctl is a small, opinionated layer over systemdkit. It starts isolated transient services, then delegates lifecycle and inspection operations to systemd over D-Bus. It does not shell out to systemctl and it does not use Docker.

Example

{:ok, instance} =
  Unitctl.start(
    name: "demo-worker",
    command: ["/usr/bin/env", "sleep", "60"],
    description: "Demo worker",
    resources: %{memory_max: 256 * 1024 * 1024, tasks_max: 64},
    sandbox: %{no_new_privileges: true, private_tmp: true}
  )

{:ok, state} = Unitctl.inspect(instance)
:ok = Unitctl.stop(instance)

This package is intentionally higher-level than systemdkit: systemdkit exposes systemd APIs; unitctl exposes runtime/app controls.

Summary

Functions

Reads common systemd state for an instance or unit name.

Restarts an instance or unit name.

Starts a transient systemd service from a Unitctl.Spec or keyword list.

Reads runtime stats for an instance or unit name.

Stops an instance or unit name.

Functions

inspect(instance_or_unit, opts \\ [])

@spec inspect(
  Unitctl.Instance.t() | String.t(),
  keyword()
) :: {:ok, Systemd.UnitState.t()} | {:error, term()}

Reads common systemd state for an instance or unit name.

restart(instance_or_unit, opts \\ [])

@spec restart(
  Unitctl.Instance.t() | String.t(),
  keyword()
) :: :ok | {:ok, Systemd.Job.t()} | {:error, term()}

Restarts an instance or unit name.

start(spec)

@spec start(Unitctl.Spec.t() | keyword() | map()) ::
  {:ok, Unitctl.Instance.t()} | {:error, term()}

Starts a transient systemd service from a Unitctl.Spec or keyword list.

stats(instance_or_unit, opts \\ [])

@spec stats(
  Unitctl.Instance.t() | String.t(),
  keyword()
) :: {:ok, Unitctl.Stats.t()} | {:error, term()}

Reads runtime stats for an instance or unit name.

Stats are sourced from systemd/cgroup D-Bus properties. Some fields may be nil when the host systemd version does not expose the property or when the corresponding accounting feature is disabled for the unit.

stop(instance_or_unit, opts \\ [])

@spec stop(
  Unitctl.Instance.t() | String.t(),
  keyword()
) :: :ok | {:ok, Systemd.Job.t()} | {:error, term()}

Stops an instance or unit name.