LFCS Certification System Service Management (systemd) 4 — Questions and Answers
Question 1: Which command shows the dependency tree for a given systemd unit?
- systemctl deps graphical.target
- systemctl list-dependencies graphical.target (Correct answer)
- systemctl show --dependencies graphical.target
- systemd-analyze deps graphical.target
Correct answer: systemctl list-dependencies graphical.target
`systemctl list-dependencies` displays a tree of all units required or wanted by the specified unit.
Question 2: A service needs to start only after the network is fully up with a routable address. Which directive and value should be used?
- After=network.target
- After=network-online.target (Correct answer)
- Requires=network.target
- Wants=network-pre.target
Correct answer: After=network-online.target
`After=network-online.target` ensures the service waits until at least one network interface has a routable address, unlike `network.target` which only means networking was initialized.
Question 3: What is the purpose of a systemd socket unit (.socket)?
- It configures kernel socket buffers for a service
- It enables socket-based activation, starting the service only when a connection arrives (Correct answer)
- It monitors open file descriptors for a service
- It creates a Unix socket file for IPC between services
Correct answer: It enables socket-based activation, starting the service only when a connection arrives
Socket activation means systemd listens on the socket and only launches the associated service when a client connects, enabling on-demand startup.
Question 4: Which `systemd-analyze` subcommand shows how long each unit took to start during the last boot?
- systemd-analyze time
- systemd-analyze blame (Correct answer)
- systemd-analyze critical-chain
- systemd-analyze plot
Correct answer: systemd-analyze blame
`systemd-analyze blame` lists all units sorted by the time they took to initialize, helping identify boot slowdowns.
Question 5: You run `systemctl mask httpd`. What is the effect?
- The service is disabled and its unit file is deleted
- The unit is symlinked to /dev/null, preventing it from being started manually or automatically (Correct answer)
- The service is stopped and its autostart is removed
- The unit file is moved to /etc/systemd/system/masked/
Correct answer: The unit is symlinked to /dev/null, preventing it from being started manually or automatically
Masking creates a symlink from the unit name to `/dev/null`, making it impossible to start by any means until explicitly unmasked.
Question 6: Which environment variable or mechanism does a service of `Type=notify` use to signal readiness to systemd?
- Writing a PID file specified by PIDFile=
- Calling sd_notify(3) with READY=1 via the $NOTIFY_SOCKET (Correct answer)
- Sending SIGRTMIN+0 to systemd's PID
- Touching the file /run/systemd/service-ready
Correct answer: Calling sd_notify(3) with READY=1 via the $NOTIFY_SOCKET
With `Type=notify`, the service calls `sd_notify(READY=1)` through the socket path provided in `$NOTIFY_SOCKET`, telling systemd it has finished initializing.
Question 7: Which journalctl option follows new log entries in real time, similar to `tail -f`?
- journalctl -w
- journalctl -f (Correct answer)
- journalctl --stream
- journalctl --tail
Correct answer: journalctl -f
`journalctl -f` (--follow) continuously outputs new journal entries as they are written, equivalent to `tail -f` for syslog.
Which command shows the dependency tree for a given systemd unit?