Basic commands
bash
systemctl status nginx # current unit state + recent log lines
sudo systemctl start nginx # start
sudo systemctl stop nginx # stop (graceful: SIGTERM -> SIGKILL after TimeoutStopSec)
sudo systemctl restart nginx # = stop + start
sudo systemctl reload nginx # send [[signals]] SIGHUP - reload config without restarting
sudo systemctl enable nginx # start at boot
sudo systemctl disable nginx # do not start at boot
sudo systemctl enable --now nginx # enable + start in one command
Viewing units
bash
systemctl # all loaded and active units
systemctl list-units --type=service # services only
systemctl list-units --state=failed # failed units
systemctl list-unit-files # all known units (including disabled)
systemctl is-active nginx # active / inactive / failed (for scripts)
systemctl is-enabled nginx # enabled / disabled
cgroup tree
bash
systemctl status nginx # bottom section: Tasks, Memory, CPU, and cgroup path
systemd-cgtop # top-style view by [[cgroups]]
systemd-cgls # cgroup tree
Where unit files live
/etc/systemd/system/- your local files and drop-ins (highest priority)/lib/systemd/system/or/usr/lib/systemd/system/- files from packages
After editing:
bash
sudo systemctl daemon-reload # re-read unit files
sudo systemctl restart <unit> # apply changes
Overriding without editing the original
bash
sudo systemctl edit nginx
# -> opens an editor for the drop-in: /etc/systemd/system/nginx.service.d/override.conf
# -> you can override individual settings in the [Service] section
This is the right approach. The original package unit stays untouched.
Other subcommands
bash
systemctl list-timers # active timers (cron replacement)
systemctl reboot / poweroff # reboot / shut down
systemctl --user start foo # user-level systemd (per-user)
systemctl mask <unit> # prevent a unit from starting at all (even as a dependency)
Using journalctl together
Logs go to a separate binary, cmd-journalctl:
bash
journalctl -u nginx -f # tail logs for a specific unit
journalctl -u nginx --since today