sourceconditiontarget

Description

The systemd resource reads and writes a single option inside a section of a systemd unit file, addressed by section name and option name rather than by line:

[Service]
ExecStart=/usr/bin/myapp --version=1.2.3
Restart=always

Here section: Service and option: ExecStart address the first line.

source

Returns the option’s value.

condition

Checks that the option holds value, or the source output when value is unset.

target

Updates the option.

Parameters

NameTypeDescriptionRequired
filestring

file specifies the systemd unit file path to manipulate

compatible: * source * condition * target

remark: * supports absolute or relative path

indexinteger

index specifies which matching option to read or update when the same option is defined multiple times. It starts at 0, so index 0 selects the first match, index 1 selects the second match, and so on. If unset then a condition or a target matches every occurrences.

compatible: * source * condition * target

default: 0

optionstring

option specifies the key within the section to read or update, such as “ExecStart”.

compatible: * source * condition * target

sectionstring

section specifies the unit file section to interact with, such as “Unit”, “Service”,

compatible: * source * condition * target

valuestring

value specifies the value for a specific option.

compatible: * condition * target

default: When used from a condition or a target, the default value is set to the associated source output.

file, section and option are all mandatory - each missing one is reported as the attribute 'spec.<name>' is required.. file takes an absolute or relative path.

index

systemd allows the same option to appear several times in a section, and index picks one, counting from zero. A negative value is rejected with the attribute 'spec.index' must be greater than or equal to 0.

Its default differs by stage: a source reads the first occurrence, while a condition and a target with index unset match every occurrence. Set it explicitly when a unit file repeats an option (ExecStartPre and Environment commonly do) and you only mean one of them.

value

Defaults to the source output.

Limitations

Important

The unit file is rewritten from its parsed form, so all comments are dropped when a target changes something. If you need them preserved, drive the edit with the "File" resource and a matchpattern/replacepattern pair, or say so on the issue tracker.

This resource edits unit files as text. It does not reload the daemon or restart units (no systemctl daemon-reload is issued, so a change applied by Updatecli takes effect only once something else reloads systemd).

Example

# updatecli.yaml
sources:
  default:
    name: Get value from systemd configuration
    kind: systemd
    spec:
      file: "wg.container"
      section: "Container"
      option: Image

conditions:
  default:
    name: Test if source output exist in systemd configuration
    kind: systemd
    spec:
      file: "wg.container"
      section: "Container"
      option: Image

targets:
  default:
    name: Update systemd configuration
    kind: systemd
    disablesourceinput: true
    spec:
      file: "wg.container"
      section: "Container"
      option: Volume
      value: "xxx"