You can override the $SYSTEMD_EDITOR
environment variable to use a different command other than your editor when running systemctl edit
.
For instance, using something like SYSTEMD_EDITOR='cp /path/to/source.file'
seems to work OK (even though it's pretty ugly, expecting the last argument to be appended there by systemd!)
For your particular case, you could use:
$ { echo "[Service]";
echo "ExecStartPre=/bin/sleep 5";
} >~/tmp/sddm-override.conf
$ sudo env SYSTEMD_EDITOR="cp $HOME/tmp/sddm-override.conf" systemctl edit sddm
But all that systemctl edit
really does is create an override file (in its case, named override.conf
) under the /etc/systemd/system/<service>.service.d/
directory, which is created if it does not exist... So doing that directly is also a totally accepted approach. (See mentions of "drop-in" and "override" in the man page for systemd.unit for more details.)
So, in your case, this would be an appropriate solution:
$ sudo mkdir -p /etc/systemd/system/sddm.service.d/
$ { echo "[Service]";
echo "ExecStartPre=/bin/sleep 5";
} | sudo tee /etc/systemd/system/sddm.service.d/10-startup-delay.conf
$ sudo systemctl daemon-reload
Which drops a file with the expected contents in the "drop-in" directory for your unit, in which case you can also name it appropriately after what it tries to accomplish.
UPDATED: As @GracefulRestart points out, you need a systemctl daemon-reload
after adding a drop-in directly.