systemctl
running the servicessystemctl is how services are managed on a systemd machine. It keeps two things apart that are easy to confuse: whether a service is running now, and whether it will be started at boot. start and stop change the first; enable and disable change the second.
"Active" is about this moment; "enabled" is about the next boot. A service can be either without the other.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
The path is the unit file systemd read. "enabled" means it will be started automatically on the next boot.
Running, and for how long. A service that crashed reads "failed" here, with the exit code beside it.
If this process exits, systemd considers the service stopped and applies its restart policy.
Every process the service started is listed, so nothing is left behind when it is stopped.
Switches
A switch changes how the command behaves. These are the ones used day to day; man systemctl lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
--now- With enable or disable, also start or stop the service immediately.
--failed- List only the units that have failed.
-t TYPE- Limit a listing to one unit type, for example -t service.
-a- All: include units that are loaded but inactive.
--user- Talk to your own user’s service manager instead of the system’s.
--no-pager- Print straight to the terminal instead of opening a pager.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
sudo systemctl restart nginxStops and starts the service. "reload" re-reads the configuration without dropping connections, where the service supports it.
sudo systemctl enable --now nginxStarts it now and sets it to start at every boot, in one step.
systemctl --failedLists every unit that is in a failed state — the first thing to check after a reboot.
journalctl -u nginx -n 50The last fifty log lines the service wrote — where the reason for a failure usually is.
In cybersecurity
Every enabled service is code that starts by itself and keeps running. The list of them is the machine's standing attack surface.
A stopped service comes back at reboot unless it is also disabled. "systemctl list-unit-files --state=enabled" is the list to prune.
A new unit file is a favourite way for an intruder to survive a reboot. Unfamiliar entries under /etc/systemd/system deserve a close look.
A unit can set User=, and sandboxing options such as ProtectSystem= and NoNewPrivileges= limit what a compromised service can reach.