Free Linux+ Systemd Service Management Questions and Answers — Questions and Answers
Question 1: A system administrator needs to ensure that the `nginx` web server starts automatically upon system boot. Which of the following commands will accomplish this?
- systemctl start nginx
- systemctl boot nginx
- systemctl enable nginx (Correct answer)
- systemctl load nginx
Correct answer: systemctl enable nginx
The `systemctl enable <service_name>` command creates the necessary symbolic links in the systemd directories to ensure that the specified service is started automatically at boot time. The `start` command only starts the service for the current session.
Question 2: After modifying the configuration file for a running service, which `systemctl` command should be used to apply the changes without stopping the service if possible?
- systemctl restart httpd
- systemctl reload httpd (Correct answer)
- systemctl update httpd
- systemctl refresh httpd
Correct answer: systemctl reload httpd
The `systemctl reload <service_name>` command tells the service to reload its configuration files without a full restart. This allows for configuration changes to be applied without interrupting the service's operation, which is preferable to a `restart` that stops and starts the entire process.
Question 3: A Linux administrator is troubleshooting a service named `customapp.service` that is failing to start. Which command will provide detailed information about the service's status, including recent log entries?
- systemctl show customapp.service
- systemctl list-units --type=service
- systemctl status customapp.service (Correct answer)
- systemctl is-failed customapp.service
Correct answer: systemctl status customapp.service
The `systemctl status <service_name>` command provides a comprehensive overview of a service's current state, including whether it is active, its PID, and the most recent log messages from the journal related to that unit, which is crucial for troubleshooting.
Question 4: Which of the following commands prevents a service from being started, either manually or by another service, by creating a symlink to `/dev/null`?
- systemctl stop cron.service
- systemctl disable cron.service
- systemctl mask cron.service (Correct answer)
- systemctl kill cron.service
Correct answer: systemctl mask cron.service
The `systemctl mask <service_name>` command is a stronger version of `disable`. It creates a symbolic link from the service's unit file to `/dev/null`, making it impossible for systemd to start the service until it is unmasked. `disable` only prevents it from starting at boot.
Question 5: A system administrator has created a new systemd unit file at `/etc/systemd/system/newapp.service`. What is the immediate next step required to make systemd aware of this new service file before it can be started or enabled?
- systemctl daemon-reload (Correct answer)
- systemctl restart systemd
- systemctl reenable newapp.service
- systemctl daemon-reexec
Correct answer: systemctl daemon-reload
Whenever a new unit file is created or an existing one is modified on disk, the `systemctl daemon-reload` command must be run. This command tells the systemd manager to reload its configuration from the disk, making it aware of the changes.
Question 6: To view all available service unit files on the system and see their current state (e.g., enabled, disabled, static), which command should be used?
- systemctl list-units --type=service
- systemctl show --all --type=service
- systemctl list-dependencies --type=service
- systemctl list-unit-files --type=service (Correct answer)
Correct answer: systemctl list-unit-files --type=service
The `systemctl list-unit-files` command is used to list all available unit files and their status. Appending `--type=service` filters this list to show only service units. In contrast, `list-units` only shows units that are currently loaded into memory.
A system administrator needs to ensure that the `nginx` web server starts automatically upon system boot.
Which of the following commands will accomplish this?