Configure system service states according to persistent startup requirements.
Scenario
Install the httpd package on the system.
Configure the web service to automatically start upon system boot.
Start the service immediately without executing a separate command.
Verify that the unit is active and operational
Solution
Install the unit
dnf install -y httpd
Enable and start the service in a single command
systemctl enable --now httpd
Verify that the unit is active and operational
systemctl is-active httpd
systemctl is-enabled httpd
Modify systemd unit behaviors using drop-in override files without editing default vendor unit files directly.
Scenario
Configure the httpd.service to automatically restart whenever its main process is unexpectedly terminated or crashes.
Ensure the system waits 5 seconds before attempting a restart.
Apply the changes to the systemd manager configuration without rebooting.
Test the durability of your configuration by forcibly terminating the primary httpd process and checking if systemd restores it automatically.
Solution
Open unit file by using vim text editor
sudo EDITOR=vim systemctl edit httpd.service
Edit file
### Anything between here and the comment below will become the contents of the drop-in file
[Service]
Restart=always
RestartSec=5s
### Edits below this comment will be discarded
Save and exit
Esc --> :wq --> Enter
Reload systemd manager configuration
sudo systemctl daemon-reload
Verify the edited content of unit file
Drag to bottom
Press q to exit
systemctl cat httpd.service
Restart the unit
sudo systemctl restart httpd.service
Find the Process ID of main process (2nd column)
The process ID which running as root (1st column) is the main process.
ps aux | grep http
Kill the main process
kill -9 [Process ID]
kill -9 5621
Check service status to verify it automatically restarted
Press q to exit
systemctl status httpd
Completely prevent administrative or automated activation of an unwanted service.
Scenario
Ensure the httpd service is completely prevented from starting, even if requested by another dependent service or manually invoked by a junior administrator.
Verify that manual attempts to start httpd fail explicitly with a unit masked error.
Solution
Stop the service
systemctl stop httpd
Mask the service
systemctl mask httpd
Check service status
Press q to quit
systemctl status httpd
Start the service
Terminal will return error: Failed to start httpd.service: Unit httpd.service is masked.
systemctl start httpd
Cleanup
systemctl unmask httpd
sudo systemctl disable httpd.service
sudo rm -rf /etc/systemd/system/httpd.service.d
sudo dnf remove -y httpd
sudo systemctl daemon-reload
Inspect active system units and trace service dependencies for troubleshooting.
Scenario
Generate a list of all active timer units currently scheduled on the system.
Identify all operational unit dependencies for sshd.service to evaluate what units are required prior to its execution.
List all installed service unit files on the system to check for disabled or unconfigured services.
Solution
systemctl list-units -t timer
systemctl list-dependencies sshd.service
systemctl list-unit-files -t service
Press q to exit