Systemd.UnitFile (systemd v0.1.0-pre.1)

Copy Markdown View Source

Loss-aware representation of a systemd unit file.

Unit files preserve ordering and duplicate directives. They are intentionally not represented as maps because repeated directives and reset directives such as ExecStart= are meaningful in systemd syntax.

Summary

Functions

Appends a directive to the last matching section, creating the section if needed.

Deletes matching directives from a section.

Returns all directive values matching a section and directive name.

Parses unit file text.

Parses unit file text, raising on failure.

Replaces all matching directives in a section with a single directive.

Builds a service unit file from common Unit, Service, and Install sections.

Renders a unit file.

Validates a unit file.

Types

entry()

t()

@type t() :: %Systemd.UnitFile{entries: [entry()]}

Functions

append(unit_file, section, name, value)

@spec append(t(), String.t(), String.t(), String.t()) :: t()

Appends a directive to the last matching section, creating the section if needed.

delete(unit_file, section, name)

@spec delete(t(), String.t(), String.t()) :: t()

Deletes matching directives from a section.

get_all(unit_file, section, name)

@spec get_all(t(), String.t(), String.t()) :: [String.t()]

Returns all directive values matching a section and directive name.

parse(text)

@spec parse(String.t()) :: {:ok, t()} | {:error, term()}

Parses unit file text.

parse!(text)

@spec parse!(String.t()) :: t()

Parses unit file text, raising on failure.

put(unit_file, section, name, value)

@spec put(t(), String.t(), String.t(), String.t()) :: t()

Replaces all matching directives in a section with a single directive.

service(opts)

@spec service(keyword()) :: t()

Builds a service unit file from common Unit, Service, and Install sections.

to_string(unit_file)

@spec to_string(t()) :: String.t()

Renders a unit file.

validate(unit_file, type \\ nil)

@spec validate(t(), String.t() | atom() | nil) ::
  :ok | {:error, [Systemd.UnitFile.ValidationError.t()]}

Validates a unit file.