RH124 Ch 9: Controlling Services with systemd

systemd is PID 1. It starts everything else as units: .service (daemons), .socket, .timer, .target (groups of units) and more.

Everyday commands - systemctl status sshd — state, main PID and the last log lines. - systemctl start|stop|restart|reload httpd — affects now only. - systemctl enable|disable httpd — affects boot only. enable --now / disable --now do both. - systemctl is-active httpd, systemctl is-enabled httpd — quick yes/no checks. - systemctl mask nfs-server — link the unit to /dev/null so nothing can start it; unmask reverts. - systemctl list-units --type=service, systemctl --failed, systemctl list-unit-files. - systemctl cat unit shows the unit file; after editing unit files run systemctl daemon-reload.

Targets replace runlevels: multi-user.target (text server) and graphical.target (desktop). - systemctl get-default / systemctl set-default multi-user.target. - systemctl isolate rescue.target switches now.

Logs for a service: journalctl -u httpd, with -f to follow or -b for this boot.

Exam traps - Starting a service but not enabling it — after the examiner's reboot it is gone. - disable does not stop a running service; use disable --now. - reload keeps connections and only rereads configuration; not every service supports it.