Skip to content

3.3 Service Management with Systemd

Systemd is the init system used by almost all modern major distributions. It manages “Units”, most commonly “Service Units” (.service). It replaces older init systems and manages processes (see [[/en/module-2/5-processes|Process Control]]) more robustly.

The main tool for interacting with systemd.

ActionCommandExplanation
Startsudo systemctl start nginxStart service now.
Stopsudo systemctl stop nginxStop service now.
Restartsudo systemctl restart nginxStop, then start.
Reloadsudo systemctl reload nginxReload config without stopping (zero downtime).
Enablesudo systemctl enable nginxStart automatically on boot.
Disablesudo systemctl disable nginxDo not start on boot.
Statussystemctl status nginxCheck if running, enabled, and view latest logs.

Cheatsheet: The “Enable and Start” Combo

Section titled “Cheatsheet: The “Enable and Start” Combo”

You often want to do both.

sudo systemctl enable --now nginx

Service definitions live in /lib/systemd/system/ (defaults) and /etc/systemd/system/ (custom overrides).

  1. Investigate SSH:
    • Check the status of the SSH service: systemctl status ssh (or sshd).
    • Is it active? Is it enabled?
  2. Manage a Dummy Service:
    • Install apache2 or nginx if you can, or pick an existing service like cron.
    • Stop the service. Verify it’s stopped.
    • Start it again.
    • Disable it (so it won’t start on boot).
    • Enable it again.
  3. Logs:
    • Use journalctl -u ssh (or sshd) to view logs specifically for that service.