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: /etc/systemd/system/service.d/ gives every service the same setting

Systemd
~/tips/tip-systemd-top-level-dropin-service-d

sudo mkdir -p /etc/systemd/system/service.d

A type-level drop-in folder applies one setting to all units of a type.

Most drop-in advice is about one unit, like nginx.service.d. systemd also has a version that hits every service at once, and I like it for settings you want everywhere.

sudo mkdir -p /etc/systemd/system/service.d
sudo nano /etc/systemd/system/service.d/10-all.conf

systemd.unit(5) calls this a top-level drop-in: a directory named after the unit type, here service.d/, applies to all matching unit files. The manual’s example puts OnFailure=failure-handler@%N.service in /etc/systemd/system/service.d/10-all.conf, so every service gets a failure handler. After systemctl daemon-reload, all services have the new dependency.

The file must end in .conf. Files from the different directories are merged in lexicographic order of their names, and a drop-in in /etc/ beats one in /run/, which beats one in /usr/lib/.

The caveat is precedence. The manual says files in type.d/ have lower precedence than files in the override directory of one specific unit. So myapp.service.d/ can still overrule your global line, which is exactly what you want for exceptions.

The same example warns about template units. Their instances get the dependency too, which can create a recursive chain. systemd tries to detect and remove these automatically. If that fails, the manual suggests symlinking the drop-in of the affected instance to /dev/null. Use systemctl cat on a service to see which drop-ins it picked up.

Further reading: systemd.unit: drop-in directories and Example 3

More Systemd tips [Service] [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min sudo bootctl set-oneshot ID All Systemd tips (88) All topics

Link