brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemctl edit changes a service without touching the original

Systemctl
~/tips/tip-linux-systemctl-edit

sudo systemctl edit nginx

Lets you change a systemd service in a separate file that updates will not overwrite.

I would not edit a unit file under /lib/systemd/system. The next package update can overwrite it, and then your change is gone without a word.

Use a drop-in instead:

sudo systemctl edit nginx

This opens an empty editor. Whatever you write is saved as override.conf in /etc/systemd/system/nginx.service.d/, and systemd reloads its configuration when you save. For example:

[Service]
Restart=on-failure
RestartSec=5

Check the merged result with systemctl cat nginx, which shows the original unit and every drop-in below it.

The caveat: settings that can appear several times, like ExecStart=, are added to the existing ones. To replace them, first write an empty ExecStart= line and then your own. Running services need a restart before they pick up the change.

I like this because it keeps my changes small and visible. Three lines in a drop-in file are easier to review later than a modified copy of the whole unit. And if I want to go back, I delete one file, or run systemctl revert nginx, and the service is back to what the package shipped.

Further reading: systemctl man page, systemd.unit man page, On this site: journalctl –vacuum-size caps how much log space you keep, On this site: systemctl list-timers is cron's answer inside systemd

More Systemctl tips sudo systemctl daemon-reload systemctl list-units --type=service --state=running systemctl -H [email protected] status nginx sudo systemctl reboot --firmware-setup systemctl list-jobs All Systemctl tips (9) All topics

Link