Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 16Naam in de cursus: Controlling Services and Daemons

Control services and daemons with systemd

A daemon is a program that runs in the background and waits for work: the web server, SSH, the time service. On RHEL, systemd starts them at boot, watches them, restarts them, and writes their logs. systemctl is the one tool to control all of it.

  • 7 Lessen
  • 7 Commando's
  • 1 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • Services starten, stoppen en inschakelen met systemctl

16.1

Know systemd and units

systemd manages units. A unit is anything systemd controls; its type is the end of its name.

Unit typeEnds withExampleWhat it is
Service.servicesshd.serviceA daemon or a one-time task
Socket.socketcockpit.socketStarts a service when a connection comes
Timer.timerdnf-makecache.timerStarts a service at a time (like cron)
Target.targetmulti-user.targetA group of units, a "system state"
Mount.mounthome.mountA mounted file system
systemctl
systemctl list-units --type=service
systemctl list-units --type=service --state=running
systemctl list-unit-files --type=service
systemctl --failed

Onthoud

You can leave out .service: systemctl status sshd means sshd.service.

16.2

Read the status of a service

systemctl status answers three questions: Is it enabled at boot? Is it active now? What did it log last?

systemctl status sshd
● sshd.service - OpenSSH server daemon
     Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
     Active: active (running) since Mon 2026-10-27 08:01:12 +03; 3h 40min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
   Main PID: 1022 (sshd)
      Tasks: 1 (limit: 23138)
     Memory: 5.2M
        CPU: 312ms
     CGroup: /system.slice/sshd.service
             └─1022 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
 
Oct 27 11:30:44 server1 sshd[4318]: Accepted publickey for student from 192.168.122.1 port 50122 ssh2
You seeMeaning
enabled / disabledStarts / does not start at boot
active (running)Runs now
active (exited)A one-time task that finished OK
inactive (dead)Not running
failedCrashed or could not start — read the log lines
staticCan not be enabled; another unit starts it
maskedBlocked: can not start at all

For scripts there are short yes/no checks:

systemctl is-active sshd
active
systemctl is-enabled sshd
enabled
systemctl is-failed httpd

16.3

Start, stop and restart

start / stop change the service now. They do not change what happens at the next boot.

systemctl start httpd
systemctl stop httpd
systemctl restart httpd
systemctl reload httpd
systemctl reload-or-restart httpd
systemctl try-restart chronyd
CommandWhat it does
restartStop and start: new process, short break for users
reloadRead the config again without stopping (only if the service supports it)
reload-or-restartReload if possible, else restart
try-restartRestart only if it runs already

Op het werk

After a config change, check the syntax first (httpd -t, sshd -t, nginx -t), then reload. A broken config plus restart = the service is down.

16.4

Enable a service at boot

enable makes the service start at every boot. --now also starts it at once. disable does the opposite.

systemctl enable httpd
Created symlink '/etc/systemd/system/multi-user.target.wants/httpd.service' → '/usr/lib/systemd/system/httpd.service'.
systemctl enable --now httpd
systemctl disable --now httpd
systemctl is-enabled httpd

Examentip

A task says "the service must run and start after a reboot"? Always systemctl enable --now SERVICE. Then check with systemctl status.

Onthoud

start = now. enable = at boot. enable --now = both.

16.5

Block a service with mask

mask links a unit to /dev/null, so nobody — not even another service — can start it. Use it for services that must never run.

systemctl mask --now nftables
Created symlink '/etc/systemd/system/nftables.service' → '/dev/null'.
systemctl start nftables
Failed to start nftables.service: Unit nftables.service is masked.
systemctl unmask nftables

Notitie

firewalld and the nftables service both load firewall rules. When you use firewalld, masking nftables stops anybody from starting the second one by mistake.

16.6

Find why a service fails

The answer is almost always in the journal of the service.

systemctl status httpd -l --no-pager
journalctl -u httpd -n 50 --no-pager
journalctl -u httpd -b -p err
journalctl -u httpd -f
httpd -t
systemctl list-dependencies httpd
systemctl cat httpd

A good order of checks:

  1. systemctl status SERVICE — the last log lines and the exit code.
  2. journalctl -u SERVICE -n 50 — more of the log.
  3. Check the config syntax with the program's own test option.
  4. Check the port: is another program already on it? ss -tlpn.
  5. Check SELinux: ausearch -m AVC -ts recent (explained in Protect services with SELinux).

16.7

Know where unit files live

Unit files from packages are in /usr/lib/systemd/system/. Your own files and changes go to /etc/systemd/system/ — they win.

systemctl cat sshd
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
After=network.target sshd-keygen.target
[Service]
ExecStart=/usr/sbin/sshd -D $OPTIONS
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl edit httpd
systemctl daemon-reload
  • systemctl edit SERVICE opens an empty drop-in file (/etc/systemd/system/SERVICE.d/override.conf). Only your lines change the unit; package updates do not overwrite them.
  • After you change a unit file by hand, run systemctl daemon-reload.

More: Write your own service.

Oefenen

Alle commando's in dit hoofdstuk