systemd is the init and service manager on essentially every modern Linux distro. The day-to-day surface for an operator is systemctl plus a handful of file paths. This article is the quick-reference we hand to new operators on day one: the commands that come up dozens of times a day, the flags that turn a frustrating debug into a fast one, and the patterns we use for writing unit files. For the longer-form patterns (templated units, timer integration, hardening directives), the deeper article in our KB is the next stop.
How to verify
What is running, what is enabled, what failed.
systemctl list-units --type=service --state=running
systemctl list-units --type=service --state=failed
systemctl list-unit-files --state=enabled
systemctl --failed
systemctl is-active nginx postgresql
systemctl is-enabled nginx postgresql
systemctl --failed is the single most useful query when something is wrong on a host you do not know — it lists every unit in failure state.
What’s happening
A unit is a description of something systemd can manage: a service, a socket, a mount, a device, a timer. The most common is a service. Each unit has a unit file — a small INI-style description of what to run, when, with what privileges, what to do if it crashes. Distros ship unit files in /lib/systemd/system/ or /usr/lib/systemd/system/. Local overrides live in /etc/systemd/system/. Drop-in fragments under /etc/systemd/system/<unit>.d/*.conf extend or override specific settings without rewriting the whole file.
systemctl is the front end. It loads unit files, computes the dependency graph, and starts/stops/restarts units while honoring Requires, Wants, After, Before relations.
journalctl is the companion log reader — every unit’s stdout/stderr goes into journald and is queryable by unit, time range, priority, or boot. See journalctl-log-reading for the dedicated reference.
The procedure
-
Start, stop, restart, reload.
sudo systemctl start nginx sudo systemctl stop nginx sudo systemctl restart nginx sudo systemctl reload nginx # SIGHUP, no downtime — only if the unit declares ExecReload sudo systemctl restart nginx --no-block # return immediately, do not waitreloadis what you want for nginx config changes — it re-reads the config without dropping connections.restartdrops them. -
Enable / disable at boot. A unit that is running now is not necessarily a unit that comes up after reboot.
enablecreates the symlink that makes it start automatically.sudo systemctl enable nginx sudo systemctl enable --now nginx # enable and start in one step sudo systemctl disable nginx sudo systemctl disable --now nginx # disable and stop--nowis the small flag every operator wishes they had known earlier. -
Read status and logs together.
statusgives the live state and the last ~10 log lines.systemctl status nginx --no-pager -n 30 journalctl -u nginx --since "10 minutes ago" --no-pager journalctl -u nginx -fjournalctl -fis the tail-follow on a unit’s logs. -
Mask a unit you want to forcibly disable.
masksymlinks the unit to/dev/nullso no one can accidentally start it.sudo systemctl mask postfix # later: sudo systemctl unmask postfixUseful for “this distro insists on installing X but we never run it.”
-
Create a drop-in to override one setting. Avoid editing the shipped unit file — drop-ins survive package upgrades.
sudo systemctl edit nginx # opens an editor; type: [Service] LimitNOFILE=65535systemctl editwrites/etc/systemd/system/nginx.service.d/override.conf. Then:sudo systemctl daemon-reload sudo systemctl restart nginx systemctl cat nginx | grep -i nofilesystemctl cat <unit>shows the resolved unit content — base file plus all drop-ins, in order. -
Write a minimal unit file from scratch. For an application your team owns:
# /etc/systemd/system/app.service [Unit] Description=Stack Harbor sample application After=network-online.target Wants=network-online.target [Service] Type=simple User=app Group=app WorkingDirectory=/srv/app ExecStart=/usr/local/bin/app --config /etc/app/config.toml Restart=on-failure RestartSec=5 StandardOutput=journal StandardError=journal # Modest hardening NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict ReadWritePaths=/var/lib/app /var/log/app ProtectHome=true [Install] WantedBy=multi-user.targetThen:
sudo systemctl daemon-reload sudo systemctl enable --now app journalctl -u app --since=now -f -
Debugging a failed unit. The sequence:
systemctl status app --no-pager journalctl -u app -p err --since "1 hour ago" systemctl cat app systemd-analyze verify /etc/systemd/system/app.servicesystemd-analyze verifyparses the unit file and reports syntax/semantics issues. The exit code is non-zero if anything is wrong; the diagnostic is more specific than “failed to start.” -
Restart-on-failure tuning.
Restart=on-failureis the typical setting, but on a misbehaving service it can crash-restart 100 times per minute.StartLimitIntervalSec=andStartLimitBurst=bound that:[Unit] StartLimitIntervalSec=60 StartLimitBurst=3 [Service] Restart=on-failure RestartSec=10“Restart up to 3 times in 60 seconds, then give up.” After the burst, the unit goes to
failedstate andsystemctl reset-failed appis needed before another start. -
For periodic jobs, use a timer not cron. Timers are systemd units that trigger another unit on a schedule. See systemd-timers-vs-cron.
-
For runtime resource limits, the directives are first-class.
MemoryMax=,CPUQuota=,TasksMax=apply via cgroups without external tooling. A misbehaving service that consumes too much memory will be killed by the cgroup OOM rather than the host OOM.
Operational notes
daemon-reloadis required after editing any unit file or drop-in. Without it,systemctl restartruns the old config.systemctl statustruncates long lines and only shows recent logs — for full output usejournalctl -u <unit>.systemctl restartof a unit withRemainAfterExit=yesis a no-op silently; the unit considers itself already done.- Services that fork themselves should declare
Type=forkingand a PIDFile; otherwise systemd loses track of the right PID. systemd-analyze blameshows what slowed down the last boot. Useful for “why does this host take 90 seconds to come up after a reboot.”
In our fleets, every application service runs under systemd with a unit file that is generated by our provisioning code from a small role template — Type, User, Restart, hardening directives, and WorkingDirectory are all uniform. That uniformity is what makes “the service is down” a clear, actionable signal across the entire Managed Operations estate.