tips
28 tips Unit files
One command, setting or habit at a time about Unit files: what it does, the line to copy and a caveat or two.
Unit files 28
-
Copies named variables from your shell into the user service manager's environment.
systemctl --user import-environment VAR1 VAR2 -
Sets how long a service gets to stop after SIGTERM before systemd sends SIGKILL.
[Service] -
A type-level drop-in folder applies one setting to all units of a type.
sudo mkdir -p /etc/systemd/system/service.d -
Terminates a service and marks it failed when it exceeds a maximum run time.
[Service] -
Let systemd create and own the data folder of a service, with the right user.
[Service] -
Let an optional preparation step fail without stopping the service from starting.
[Service] -
Give each override of a unit its own named file instead of one big override.conf.
sudo systemctl edit --drop-in=limits myapp.service -
Replace names like sh, python3 or java in log lines with the name of your service.
[Service] -
Skip a service quietly when a check command says now is not the time.
[Service] -
Back off gradually when a service keeps crashing instead of hammering it every few seconds.
[Service] -
Make systemctl reload send a signal to the main process of your own service.
ExecReload=/bin/kill -HUP $MAINPID -
Write one unit file with %i and start as many named instances of it as you need.
[Unit] -
Stop a service from showing as failed when its program exits with a harmless code.
[Service] -
Removes drop-ins and overrides of a unit so it goes back to the vendor version.
sudo systemctl revert example.service -
Keeps a service from starting before the disk or share it writes to is mounted.
sudo systemctl edit myapp.service -
Blocks a systemd service from being started by anything until you unmask it.
sudo systemctl mask --now cups.service -
Checks on the spot whether a unit's Condition lines would let it start on this machine.
systemd-analyze condition 'ConditionHost=nas*' 'ConditionVirtualization=!vm' -
Skips starting a service, without marking it failed, when a chosen file is absent.
sudo systemctl edit mysync.service -
Loads a service's environment variables from a separate file you can edit freely.
[Service] -
Makes a service start only once the network is really up, not just started.
After=network-online.target -
Keeps a run-once setup service active after its script exits, so stop runs cleanly.
RemainAfterExit=yes -
Lets a helper service follow its main service when that one stops or restarts.
sudo systemctl edit myapp-worker.service -
Sends a service's output to a normal text log file instead of the journal.
sudo systemctl edit myapp.service -
Triggers a notification unit automatically whenever another service ends up failed.
OnFailure=notify@%n.service -
Restarts a crashed service after a pause and gives up after too many quick failures.
Restart=on-failure -
Checks a unit file for unknown directives and missing binaries without starting anything.
systemd-analyze verify /etc/systemd/system/myapp.service -
Replaces the start command of a service in a drop-in by clearing the inherited one first.
ExecStart= -
Prints the unit file plus every drop-in override in application order.
systemctl cat nginx.service
Nothing in this filter yet.