Pure Elixir tools for working with systemd.
The package provides a D-Bus backed manager client, unit object/property APIs, job awaiting, installation helpers, and a loss-aware unit file parser/generator.
Examples
{:ok, units} = Systemd.list_units()
:ok = Systemd.start_unit("example.service")
{:ok, state} = Systemd.unit_state("dbus.service")
unit_file =
Systemd.UnitFile.service(
unit: [description: "Example"],
service: [exec_start: "/bin/true", type: :oneshot],
install: [wanted_by: "multi-user.target"]
)
:ok = Systemd.UnitFile.validate(unit_file, :service)Mutating calls can return {:error, %Systemd.Error{category: :permission}}
when systemd or polkit denies the D-Bus operation.
Summary
Functions
Closes a D-Bus connection process opened by this package.
Disables unit files using a short-lived connection.
Enables unit files using a short-lived connection.
Links unit files using a short-lived connection.
Lists loaded units using a short-lived connection.
Masks unit files using a short-lived connection.
Reloads systemd manager configuration using a short-lived connection.
Reloads a unit and waits for the returned job by default.
Restarts a unit and waits for the returned job by default.
Starts a unit and waits for the returned job by default.
Stops a unit and waits for the returned job by default.
Reads common state for a unit using a short-lived connection.
Unmasks unit files using a short-lived connection.
Runs a function with a short-lived systemd manager D-Bus connection.
Types
@type connection_option() :: {:bus, Systemd.DBus.bus()}
Functions
@spec close(pid()) :: :ok
Closes a D-Bus connection process opened by this package.
@spec disable_unit_files( [String.t()], keyword() ) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}
Disables unit files using a short-lived connection.
@spec enable_unit_files( [String.t()], keyword() ) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}
Enables unit files using a short-lived connection.
@spec link_unit_files( [String.t()], keyword() ) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}
Links unit files using a short-lived connection.
@spec list_units(keyword()) :: {:ok, [Systemd.Unit.t()]} | {:error, Systemd.Error.t()}
Lists loaded units using a short-lived connection.
@spec mask_unit_files( [String.t()], keyword() ) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}
Masks unit files using a short-lived connection.
@spec reload(keyword()) :: :ok | {:error, Systemd.Error.t()}
Reloads systemd manager configuration using a short-lived connection.
@spec reload_unit( String.t(), keyword() ) :: :ok | {:ok, Systemd.Job.t()} | {:error, Systemd.Error.t()}
Reloads a unit and waits for the returned job by default.
@spec restart_unit( String.t(), keyword() ) :: :ok | {:ok, Systemd.Job.t()} | {:error, Systemd.Error.t()}
Restarts a unit and waits for the returned job by default.
@spec start_unit( String.t(), keyword() ) :: :ok | {:ok, Systemd.Job.t()} | {:error, Systemd.Error.t()}
Starts a unit and waits for the returned job by default.
@spec stop_unit( String.t(), keyword() ) :: :ok | {:ok, Systemd.Job.t()} | {:error, Systemd.Error.t()}
Stops a unit and waits for the returned job by default.
@spec unit_state( String.t(), keyword() ) :: {:ok, Systemd.UnitState.t()} | {:error, Systemd.Error.t()}
Reads common state for a unit using a short-lived connection.
@spec unmask_unit_files( [String.t()], keyword() ) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}
Unmasks unit files using a short-lived connection.
@spec with_connection( keyword(), (pid() -> result) ) :: result | {:error, Systemd.Error.t()} when result: term()
Runs a function with a short-lived systemd manager D-Bus connection.