Systemd.UnitFile (systemdkit v0.1.4)

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.

Compares two unit files after normalization.

Returns all directive values matching a section and directive name.

Builds a mount unit file from common Unit, Mount, and Install sections.

Returns a normalized representation suitable for semantic-ish comparison.

Parses unit file text.

Parses unit file text, raising on failure.

Builds a path unit file from common Unit, Path, and Install sections.

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

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

Builds a socket unit file from common Unit, Socket, and Install sections.

Builds a target unit file from common Unit, Target, and Install sections.

Builds a timer unit file from common Unit, Timer, 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.

equivalent?(left, right)

@spec equivalent?(t() | String.t(), t() | String.t()) :: boolean()

Compares two unit files after normalization.

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.

mount(opts)

@spec mount(keyword()) :: t()

Builds a mount unit file from common Unit, Mount, and Install sections.

normalize(text)

@spec normalize(t() | String.t()) :: map()

Returns a normalized representation suitable for semantic-ish comparison.

This intentionally ignores trivia, directive ordering, and equivalent list spellings for directives such as Wants= and ReadWritePaths=.

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.

path(opts)

@spec path(keyword()) :: t()

Builds a path unit file from common Unit, Path, and Install sections.

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.

socket(opts)

@spec socket(keyword()) :: t()

Builds a socket unit file from common Unit, Socket, and Install sections.

target(opts)

@spec target(keyword()) :: t()

Builds a target unit file from common Unit, Target, and Install sections.

timer(opts)

@spec timer(keyword()) :: t()

Builds a timer unit file from common Unit, Timer, 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.