published
priority 10
25 min. 40 XP.
Linux Service Management. systemctl, journalctl, sysvinit
Every NCAE service is managed by systemd. You will type `systemctl restart <service>` at least once per minute during competition. This lesson is the foundation. without it, nothing in the other lessons makes sense. It also teaches `journalctl`, which is where you find out why a service REFUSES to start.
DCWF roles:
IT-411 Technical Support Specialist
IT-451 System Administrator
Services:
SSH LoginSMB LoginDNS INT FWDPostgres AccessWWW Port 80WWW ContentWWW SSL
Objectives
- Understand systemd as the init system (PID 1) and how it manages services
- Use `systemctl` to start, stop, restart, reload, enable, disable, and check status
- Use `journalctl` to read logs from any service with time filtering
- Distinguish between services (.service), targets (.target), and timers (.timer)
- Read a systemd unit file and identify ExecStart, Restart policy, and dependencies
- Know where custom unit files live: /etc/systemd/system/ (admin) vs /lib/systemd/system/ (package)
Quick reference
| Command | Purpose |
|---|---|
| systemctl status <svc> | Current status + last few log lines |
| systemctl start <svc> | Start the service now |
| systemctl stop <svc> | Stop it now |
| systemctl restart <svc> | Stop then start |
| systemctl reload <svc> | Apply config changes without stopping (if supported) |
| systemctl reload-or-restart <svc> | Prefer reload; fall back to restart |
| systemctl enable <svc> | Auto-start on boot |
| systemctl disable <svc> | Don't auto-start on boot |
| systemctl is-active <svc> | Exits 0 if active. useful in scripts |
| systemctl list-unit-files --type=service --state=enabled | All enabled services |
| systemctl list-timers --all | All systemd timers |
| systemctl cat <svc> | Print the unit file contents |
| systemctl daemon-reload | Re-read unit files after editing them |
| journalctl -u <svc> | All logs from a service |
| journalctl -u <svc> -n 50 | Last 50 lines |
| journalctl -u <svc> -f | Follow in real time (tail -f) |
| journalctl -u <svc> --since '5 minutes ago' | Time-filtered |
| journalctl -p err --since today | All errors today, any unit |
Common pitfalls
- Editing a unit file and forgetting `systemctl daemon-reload`. systemd still uses the old version
- `systemctl status` lies. it can show 'active (running)' briefly while the process dies; use `systemctl is-active` in loops
- `journalctl -u <svc>` without `-n` dumps the entire history. can be megabytes
- Confusing `enable` (auto-start on boot) with `start` (start now). they're independent
- Using `service foo restart`. still works via sysvinit shim but systemctl is the native tool
How it works (walkthrough)
# A minimal systemd service unit file # /etc/systemd/system/my-watchdog.service [Unit] Description=Keep the tarball restore loop alive After=network.target [Service] Type=simple ExecStart=/root/restore-loop.sh Restart=always # if it dies, systemd restarts it RestartSec=2 [Install] WantedBy=multi-user.target # start on boot at multi-user runlevel # After writing the file: # systemctl daemon-reload # pick up the new file # systemctl enable --now my-watchdog
Skill drills
-
1. Command to check if nginx is currently running?systemctl status nginx (or is-active nginx)
-
2. Command to reload nginx without restarting?systemctl reload nginx
-
3. Command to see why a service refused to start?journalctl -u <svc> -n 50
-
4. After editing /etc/systemd/system/foo.service, what must you run?systemctl daemon-reload
-
5. What runlevel does `multi-user.target` correspond to in sysvinit?Runlevel 3 (multi-user, no GUI)
-
6. Follow the sshd log in real time?journalctl -u sshd -f
NCAE scoreboard patterns this lesson prevents
- 2,502.8 SSH Login. Failed to connect to host: IP
- 44.4 SSH Login. The following users failed to authenticate with their public key: nills, vetomo
- 44.4 SSH Login. The following users failed to authenticate with their public key: vetomo, nills
- 36.1 SSH Login. The following users failed to authenticate with their public key: simone_weil, todd_k
- 36.1 SSH Login. The following users failed to authenticate with their public key: vetomo, todd_k
- 30.6 SSH Login. The following users failed to authenticate with their public key: claude_chevalley
- 27.8 SSH Login. The following users failed to authenticate with their public key: claude_chevalley, simone_weil
- 27.8 SSH Login. The following users failed to authenticate with their public key: nills, simone_weil
- 27.8 SSH Login. The following users failed to authenticate with their public key: nills, todd_k
- 25 SSH Login. The following users failed to authenticate with their public key: simone_weil, vetomo, claude_chevalley
- 25 SSH Login. The following users failed to authenticate with their public key: nills
- 25 SSH Login. The following users failed to authenticate with their public key: simone_weil, nills
- 22.2 SSH Login. The following users failed to authenticate with their public key: vetomo, claude_chevalley
- 22.2 SSH Login. The following users failed to authenticate with their public key: vetomo
- 19.4 SSH Login. The following users failed to authenticate with their public key: simone_weil, vetomo, nills