Systemd (systemd v0.1.0-pre.1)

Copy Markdown View Source

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

connection_option()

@type connection_option() :: {:bus, Systemd.DBus.bus()}

Functions

close(conn)

@spec close(pid()) :: :ok

Closes a D-Bus connection process opened by this package.

disable_unit_files(files, opts \\ [])

@spec disable_unit_files(
  [String.t()],
  keyword()
) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}

Disables unit files using a short-lived connection.

enable_unit_files(files, opts \\ [])

@spec enable_unit_files(
  [String.t()],
  keyword()
) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}

Enables unit files using a short-lived connection.

list_units(opts \\ [])

@spec list_units(keyword()) :: {:ok, [Systemd.Unit.t()]} | {:error, Systemd.Error.t()}

Lists loaded units using a short-lived connection.

mask_unit_files(files, opts \\ [])

@spec mask_unit_files(
  [String.t()],
  keyword()
) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}

Masks unit files using a short-lived connection.

reload(opts \\ [])

@spec reload(keyword()) :: :ok | {:error, Systemd.Error.t()}

Reloads systemd manager configuration using a short-lived connection.

reload_unit(name, opts \\ [])

@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.

restart_unit(name, opts \\ [])

@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.

start_unit(name, opts \\ [])

@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.

stop_unit(name, opts \\ [])

@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.

unit_state(name, opts \\ [])

@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.

unmask_unit_files(files, opts \\ [])

@spec unmask_unit_files(
  [String.t()],
  keyword()
) :: {:ok, Systemd.UnitFileOperation.t()} | {:error, Systemd.Error.t()}

Unmasks unit files using a short-lived connection.

with_connection(opts \\ [], fun)

@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.