LFCS Certification System Service Management (systemd) 2 — Questions and Answers
Question 1: Which systemctl command displays the current state of a service, including its active state, PID, and recent log lines?
- systemctl info sshd
- systemctl status sshd (Correct answer)
- systemctl show sshd
- systemctl inspect sshd
Correct answer: systemctl status sshd
`systemctl status sshd` shows the service's active state, PID, enabled status, and recent journal output in a human-readable format.
Question 2: What file does systemd read to determine which target to boot into by default?
- /etc/systemd/default.target
- /etc/systemd/system/default.target (Correct answer)
- /lib/systemd/system/default.target
- /etc/inittab
Correct answer: /etc/systemd/system/default.target
`/etc/systemd/system/default.target` is a symlink managed by `systemctl set-default` that determines the default boot target.
Question 3: A service unit file contains `Type=forking`. What does this mean?
- The service spawns multiple child processes and keeps all of them
- The parent process exits after forking a child, and the child becomes the main process (Correct answer)
- The service forks itself on each request
- systemd will fork the process to isolate it in a namespace
Correct answer: The parent process exits after forking a child, and the child becomes the main process
With `Type=forking`, systemd expects the parent process to exit after forking, and tracks the child (often via PIDFile=) as the main service process.
Question 4: Which directive in a [Service] section tells systemd to restart a service whenever it exits, regardless of exit code?
- Restart=always (Correct answer)
- Restart=on-failure
- RestartPolicy=always
- AutoRestart=yes
Correct answer: Restart=always
`Restart=always` causes systemd to restart the service on any exit condition, including clean exits.
Question 5: You want to see all units that have failed. Which command shows only failed units?
- systemctl --state=failed
- systemctl list-units --failed
- systemctl --failed (Correct answer)
- systemctl status --errors
Correct answer: systemctl --failed
`systemctl --failed` lists all units currently in a failed state.
Question 6: Which systemd target is the typical equivalent of SysV runlevel 3 (multi-user, no GUI)?
- multi-user.target (Correct answer)
- graphical.target
- network.target
- runlevel3.target
Correct answer: multi-user.target
`multi-user.target` corresponds to SysV runlevel 3, providing a fully operational multi-user environment without a graphical display manager.
Question 7: What does the `WantedBy=multi-user.target` line in a unit's [Install] section do when you run `systemctl enable`?
- It starts the unit immediately in multi-user.target
- It creates a symlink in multi-user.target.wants/ so the unit starts when that target is reached (Correct answer)
- It adds the unit as a hard dependency of multi-user.target
- It sets the unit's default target to multi-user.target
Correct answer: It creates a symlink in multi-user.target.wants/ so the unit starts when that target is reached
`systemctl enable` creates a symlink under `/etc/systemd/system/multi-user.target.wants/` pointing to the unit file, causing it to be pulled in at boot.
Which systemctl command displays the current state of a service, including its active state, PID, and recent log lines?