Systemd.UnitName (systemdkit v0.1.3)

Copy Markdown View Source

Pure helpers for formatting systemd unit names.

Systemd unit names are ordinary strings, but callers often need to format the same patterns repeatedly: typed names such as dbus.service, template names such as my_app@.service, and instance names such as my_app@4000.service.

This module keeps that formatting explicit without introducing a struct or a deployment-specific abstraction.

Examples

iex> Systemd.UnitName.new("dbus", :service)
"dbus.service"

iex> Systemd.UnitName.template("my_app", :service)
"my_app@.service"

iex> Systemd.UnitName.instance("my_app", 4000, :service)
"my_app@4000.service"

iex> Systemd.UnitName.ensure_type("my_app@4000", :service)
"my_app@4000.service"

iex> Systemd.UnitName.drop_type("my_app@4000.service")
"my_app@4000"

Summary

Functions

Drops the final systemd unit type suffix from a name.

Ensures a unit name has the suffix for type.

Formats a systemd instance unit name.

Formats a typed systemd unit name.

Formats a systemd template unit name.

Types

unit_type()

@type unit_type() ::
  :service | :socket | :timer | :target | :mount | :path | String.t()

Functions

drop_type(name)

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

Drops the final systemd unit type suffix from a name.

ensure_type(name, type)

@spec ensure_type(String.t(), unit_type()) :: String.t()

Ensures a unit name has the suffix for type.

instance(name, instance, type)

@spec instance(String.t(), String.Chars.t(), unit_type()) :: String.t()

Formats a systemd instance unit name.

new(name, type)

@spec new(String.t(), unit_type()) :: String.t()

Formats a typed systemd unit name.

If name already ends with the requested type suffix, it is returned unchanged.

template(name, type)

@spec template(String.t(), unit_type()) :: String.t()

Formats a systemd template unit name.