On this page
Systemd
| source | condition | target |
|---|---|---|
✔ | ✔ | ✔ |
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=alwaysHere 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 whenvalueis unset.- target
Updates the option.
Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| file | string | “file” defines the path of the systemd unit file to manipulate. compatible:
remark:
example:
| |
| index | integer | “index” defines which matching option to use when the same option is defined several times. compatible:
default: empty remark:
example:
| |
| option | string | “option” defines the key within the section to read or update, such as “ExecStart”. compatible:
remark:
example:
| |
| section | string | “section” defines the unit file section to use, such as “Unit” or “Service”. compatible:
remark:
example:
| |
| value | string | “value” defines the value of the option. compatible:
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.
indexsystemd allows the same option to appear several times in a section, and
indexpicks one, counting from zero. A negative value is rejected withthe 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
indexunset match every occurrence. Set it explicitly when a unit file repeats an option (ExecStartPreandEnvironmentcommonly do) and you only mean one of them.valueDefaults 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 |
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"
Links
systemd.unit(5) - unit file sections and options