Intermediate · 9 min · practise every command in the built-in terminal

Controlling Services

Start / stop / restart

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx      # Stop then start
sudo systemctl reload nginx       # Reload config without dropping connections

Enable / disable at boot

sudo systemctl enable nginx       # Start automatically on boot
sudo systemctl disable nginx      # Don't start on boot (doesn't stop it now)
sudo systemctl enable --now nginx # Enable AND start immediately

Mask a service (hard-disable)

sudo systemctl mask nginx         # Prevents it from being started at all, even manually
sudo systemctl unmask nginx       # Allows it again

Reload systemd itself after editing a unit file

sudo systemctl daemon-reload

Required any time you edit a .service file directly, so systemd picks up the changes.

Quick reference

CommandEffect
startRun now
stopStop now
restartStop + start
enableRun on every boot
disableDon't run on boot
statusShow current state

Practice tasks

  1. Restart the nginx service
  2. Enable nginx to start automatically at boot
  3. Stop the nginx service
  4. Mask nginx so it can't be started at all, even manually
  5. Unmask nginx so it can be started again

Commands in this lesson

Services & systemd