Systemd (systemdkit v0.1.2)

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.

Sends a Unix signal to processes belonging to a unit using a short-lived connection.

Links unit files using a short-lived connection.

Lists queued jobs using a short-lived connection.

Returns unit files known to systemd 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 if supported, otherwise restarts it.

Reloads a unit if supported, otherwise tries to restart it only if active.

Reloads a unit and waits for the returned job by default.

Resets failed state for a unit using a short-lived connection.

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.

Tries to restart a unit only if it is already active.

Returns the enablement state of a unit file using a short-lived connection.

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.

kill_unit(name, who \\ "all", signal \\ 15, opts \\ [])

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

Sends a Unix signal to processes belonging to a unit using a short-lived connection.

list_jobs(opts \\ [])

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

Lists queued jobs using a short-lived connection.

list_unit_files(opts \\ [])

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

Returns unit files known to systemd 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_or_restart_unit(name, opts \\ [])

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

Reloads a unit if supported, otherwise restarts it.

reload_or_try_restart_unit(name, opts \\ [])

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

Reloads a unit if supported, otherwise tries to restart it only if active.

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.

reset_failed_unit(name, opts \\ [])

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

Resets failed state for a unit using a short-lived connection.

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.

try_restart_unit(name, opts \\ [])

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

Tries to restart a unit only if it is already active.

unit_file_state(name, opts \\ [])

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

Returns the enablement state of a unit file using a short-lived connection.

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.