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” defines the path of the systemd unit file to manipulate.

compatible:

  • source
  • condition
  • target

remark:

  • “file” is required.
  • absolute and relative paths are supported.

example:

  • file: /etc/systemd/system/myapp.service
indexinteger

“index” defines which matching option to use when the same option is defined several times.

compatible:

  • source
  • condition
  • target

default: empty

remark:

  • it starts at 0, so index 0 selects the first match and index 1 the second.
  • it must be greater than or equal to 0.
  • when unset in a source, the first match is used.
  • when unset in a condition or a target, every match is used.

example:

  • index: 0
optionstring

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

compatible:

  • source
  • condition
  • target

remark:

  • “option” is required.

example:

  • option: ExecStart
sectionstring

“section” defines the unit file section to use, such as “Unit” or “Service”.

compatible:

  • source
  • condition
  • target

remark:

  • “section” is required.

example:

  • section: Service
valuestring

“value” defines the value of the option.

compatible:

  • condition
  • target

default: in a condition or a target, the output of the associated source.

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"