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 specifies the systemd unit file path to manipulate compatible: * source * condition * target remark: * supports absolute or relative path | |
| index | integer | 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 | |
| option | string | option specifies the key within the section to read or update, such as “ExecStart”. compatible: * source * condition * target | |
| section | string | section specifies the unit file section to interact with, such as “Unit”, “Service”, compatible: * source * condition * target | |
| value | string | 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.
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