0

I know that this is a valid systemd unit configuration file syntax:

[Unit]
RequiresMountsFor=/mnt/foo /mnt/bar
...

Recently, I've seen a multiline variant of the above:

[Unit]
RequiresMountsFor=/mnt/foo
RequiresMountsFor=/mnt/bar
...

Are these two syntaxes semantically equivalent?

I checked the RequiresMountsFor option in the systemd.unit manpage, which explicitly states: "Takes a space-separated list of absolute paths." Also there's a hint on similarities with Requires and After options. The Requires option's documentation explicitly states that the single-line and multi-line syntaxes are equivalent (for the Requires option): "This option may be specified more than once or multiple space-separated units may be specified in one option in which case requirement dependencies for all listed names will be created." So I'd guess that the same applies to RequiresMountsFor.

1 Answer 1

1

Looks like it’s equivalent indeed:

# tee /run/systemd/system/serverfault-1085820.service >/dev/null << 'EOF'
[Unit]
RequiresMountsFor=/mnt/foo
RequiresMountsFor=/mnt/bar
[Service]
ExecStart=echo hi
EOF
# systemctl daemon-reload
# SYSTEMD_PAGER=cat systemctl show -p RequiresMountsFor serverfault-1085820.service 
RequiresMountsFor=/mnt/bar /mnt/foo

This should probably be documented better in the manpage; it’s not true for all directives, as systemd.syntax(7) points out:

Various settings are allowed to be specified more than once, in which case the interpretation depends on the setting. Often, multiple settings form a list, and setting to an empty value "resets", which means that previous assignments are ignored. When this is allowed, it is mentioned in the description of the setting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.