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 mask stops a systemd unit from starting at all, not just at boot

Systemd
~/tips/tip-systemd-systemctl-mask

sudo systemctl mask --now cups.service

Blocks a systemd service from being started by anything until you unmask it.

systemctl disable sounds final, but it isn’t. It only removes the symlinks that start a unit at boot. You can still start a disabled service by hand, and another unit can still pull it in. When I want a service really gone without uninstalling the package, I reach for mask.

Masking links the unit name to /dev/null in /etc/systemd/system/. From then on every attempt to start it fails, whether it comes from you, from a dependency or from enable. The man page calls it a stronger version of disable. Add --now and the unit is stopped in the same step:

sudo systemctl mask --now cups.service
systemctl is-enabled cups.service
sudo systemctl unmask cups.service

Here is-enabled answers masked, and unmask undoes the whole thing. With --runtime the mask lives in /run and is gone after the next reboot, which is handy when you only want a service out of the way for one maintenance session.

Something else to look at: if a .socket or .timer unit still triggers the service, systemctl prints a warning that names it. My advice is to read that warning and mask the trigger too, otherwise it keeps trying and failing.

The caveat is where it works. Mask creates a symlink in /etc/systemd/system/, so it fails when a unit file with that name already sits there. That makes it a tool for units a package installed in /usr/lib/systemd/system/. For a unit you wrote yourself, disable it and stop it, or move the file away.

Further reading: systemctl(1) manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link