How to programatically modify systemd unit files?

3

I'd like to edit a systemd's unit file from a shell script. I want to change the unit's only ExecStart line. Using systemctl edit looks smart to me, but the command needs an editor set as SYSTEMD_EDITOR environment variable. Is there any SYSTEMD_EDITOR alternative which would be used like echo 'ExecStart=foo' | SYSTEMD_EDITOR=SOMETHING systemctl edit bar?

yanana

Posted 2016-04-06T10:31:25.160

Reputation: 133

Answers

5

Use systemd's "override" mechanism:

mkdir -p /etc/systemd/system/foobar.service.d
cat > /etc/systemd/system/foobar.service.d/10-my-edits.conf <<EOF
[Service]
ExecStart=
ExecStart=foo
EOF

user1686

Posted 2016-04-06T10:31:25.160

Reputation: 283 655