4.5 Given a scenario, use systemd to diagnose and resolve common problems with a Linux system.

────────────────────────────────────────────
🔧 Systemd unit types
────────────────────────────────────────────
Type Omschrijving
Service unit (.service) : Beheert een achtergrondproces.
Mount unit (.mount) : Mount een bestandssysteem.
Timer unit (.timer) : Vervangt cron voor geplande taken.
Target unit (.target) : Verzameling units, gebruikt voor boot- of servicemanagement (zoals runlevels).

────────────────────────────────────────────
📄 Service unit bestandselementen
────────────────────────────────────────────
Directive Uitleg
ExecStart : Het commando dat wordt uitgevoerd bij start.
ExecStop : Commando bij stoppen van de service.
Type : Init-methode (simple, forking, oneshot, notify, idle).
User : Gebruiker onder wie het draait.
Before=/After= : Volgorde van opstarten van andere units.
Requires= : Vereist andere unit (fout = stopt deze ook).
Wants= : Zwakke afhankelijkheid.
🔧 Bekijk/bewerk met: systemctl cat , sudo systemctl edit

────────────────────────────────────────────
⏱️ Timer units – cronvervanger
────────────────────────────────────────────
Directive Betekenis
OnCalendar= : Start op geplande tijd (zoals Mon *-*-* 10:00:00).
OnBootSec= : Wacht tijd na boot, bijv. 10min.
Unit= : De gekoppelde .service die uitgevoerd wordt.
🔧 Bekijken: systemctl list-timers, systemctl status .timer

────────────────────────────────────────────
🗂️ Mount units
────────────────────────────────────────────
Directive Betekenis
Naamgeving : /mnt/data → mnt-data.mount
What= : Apparatenamen zoals /dev/sdb1
Where= : Mountpunt zoals /mnt/data
Type= : Filesystem type zoals ext4, xfs, enz.
Options= : Optioneel: noatime, defaults, enz.
🔧 Tip: mountunits kunnen dynamisch gegenereerd worden vanuit /etc/fstab.

────────────────────────────────────────────
🎯 Targets – runlevels in systemd
────────────────────────────────────────────
Target Functie
default.target : Wat het systeem standaard laadt bij boot.
multi-user.target : Niet-grafische omgeving met netwerk.
graphical.target : Met GUI-omgeving (bijv. GNOME).
network-online.target : Wacht tot netwerkverbinding actief is.

Gebruik systemctl get-default of systemctl set-default.

────────────────────────────────────────────
🛠️ Veelvoorkomende problemen oplossen
────────────────────────────────────────────
Probleem Diagnose / Oplossing
🔍 Name resolution failure : Check systemd-resolved, resolvectl, /etc/resolv.conf.
💥 Application crash : Gebruik journalctl -u of coredumpctl.
🕒 Time-zone incorrect : timedatectl status / timedatectl set-timezone.
🐢 Langzame boot : systemd-analyze blame toont trage services.
📜 Journalproblemen : journalctl --verify, rotatie checken: /etc/systemd/journald.conf.
❌ Services starten niet : systemctl status, journalctl -xe, check dependencies (Requires/Wants).

────────────────────────────────────────────
✅ Handige systemd commando's
────────────────────────────────────────────
Commando Functie
systemctl status : Bekijk status van unit
journalctl -u : Logs van een specifieke service
systemctl enable/disable : Start bij boot aan/uit zetten
systemctl start/stop/restart : Service handmatig beheren
systemctl list-units : Lijst actieve units
systemd-analyze : Boottijd analyseren
systemctl list-timers : Actieve timers bekijken

────────────────────────────────────────────
📋 Samenvatting per onderdeel
────────────────────────────────────────────
Onderdeel Belangrijkste componenten
Unit Files : .service, .mount, .timer, .target
Configuratie : ExecStart, Type, Requires, User, Before
Timers : OnCalendar, OnBootSec, Unit
Mount : What, Where, Type, naamconventies
Troubleshooting : journalctl, systemctl, systemd-analyze