RHCSA Systemd and Service Management Questions and Answers — Questions and Answers
Question 1: A system administrator needs to troubleshoot a failing service named `httpd.service`. Which of the following commands provides the most direct and comprehensive way to view all log entries for only that specific service since the system last booted?
- systemctl status httpd.service
- cat /var/log/messages | grep httpd
- journalctl -u httpd.service -b (Correct answer)
- journalctl /usr/sbin/httpd
Correct answer: journalctl -u httpd.service -b
The `journalctl` command is the standard tool for querying the systemd journal. The `-u` flag filters the output for a specific systemd unit, and the `-b` flag restricts the output to logs from the current boot. This combination is the most precise method for this task.
Question 2: What is the key difference between disabling a service with `systemctl disable` and masking a service with `systemctl mask`?
- `disable` stops the service immediately, whereas `mask` only prevents it from starting on the next boot.
- `disable` prevents the service from starting automatically at boot, but it can still be started manually or as a dependency. `mask` links the service to `/dev/null`, preventing it from being started under any circumstances. (Correct answer)
- `disable` is a temporary action that is reset on reboot, whereas `mask` is persistent.
- `mask` removes the service's unit file from the system, while `disable` only removes the startup symlinks.
Correct answer: `disable` prevents the service from starting automatically at boot, but it can still be started manually or as a dependency. `mask` links the service to `/dev/null`, preventing it from being started under any circumstances.
`systemctl disable` removes the symlinks that cause a service to start at boot time. However, the service can still be started manually or by another dependent service. `systemctl mask` is a more forceful action that creates a symlink from the service unit file to `/dev/null`, making it impossible for systemd to load and start the service at all, even if requested manually or as a dependency.
Question 3: After creating a new systemd unit file at `/etc/systemd/system/custom.service`, a system administrator tries to start it but receives an error that the unit is not found. Which command must be run first for systemd to recognize the new unit file?
- systemctl daemon-reload (Correct answer)
- systemctl restart systemd
- systemctl refresh-units
- systemctl enable custom.service
Correct answer: systemctl daemon-reload
Whenever a systemd unit file is added, modified, or deleted on the filesystem, the `systemctl daemon-reload` command must be executed. This command instructs the systemd manager to rescan its configuration directories and reload the unit files from disk, making it aware of any changes.
Question 4: A server is currently running in the `graphical.target` (runlevel 5). An administrator needs to switch to `multi-user.target` (runlevel 3) immediately to perform maintenance, but wants the server to boot back into `graphical.target` on the next reboot. Which command will achieve this temporary change?
- systemctl set-default multi-user.target
- telinit 3
- systemctl disable graphical.target
- systemctl isolate multi-user.target (Correct answer)
Correct answer: systemctl isolate multi-user.target
The `systemctl isolate` command switches to a different target in the current session only, stopping services that are not part of the new target's dependency chain. It does not change the default target that the system will boot into. `set-default` would make the change persistent.
Question 5: After editing the main configuration file for a running web server, you need to apply the changes without dropping active user connections. Assuming the service unit supports this functionality, which command is the most appropriate?
- systemctl restart httpd.service
- systemctl reload httpd.service (Correct answer)
- systemctl kill -s SIGHUP httpd.service
- systemctl daemon-reload
Correct answer: systemctl reload httpd.service
The `systemctl reload` command sends a signal to the service to gracefully reload its configuration files without stopping and starting the main process. This is the preferred method for applying configuration changes to services that support it, as it avoids downtime.
Question 6: Which of the following commands is used to change the default target the system will boot into, making the change persistent across reboots?
- systemctl isolate graphical.target
- systemctl enable default.target --now
- systemctl set-default graphical.target (Correct answer)
- systemctl start graphical.target
Correct answer: systemctl set-default graphical.target
The `systemctl set-default` command is used to set the default target (equivalent to a runlevel) for the system to boot into. This command creates a symbolic link from `/etc/systemd/system/default.target` to the specified target unit, ensuring the setting is persistent.
A system administrator needs to troubleshoot a failing service named `httpd.service`.
Which of the following commands provides the most direct and comprehensive way to view all log entries for only that specific service since the system last booted?