Cheatography
https://cheatography.com
Controlling Services and Daemons
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Introduction to systemd
System startup and server processes are managed by the systemd System and Service Manager. This program provides a method for activating system resources, server daemons, and other processes, both at boot time and on a running system. |
Summary of systemctl commands
View detailed information about a unit state. |
systemctl status UNIT |
Stop a service on a running system. |
systemctl stop UNIT |
Start a service on a running system. |
systemctl start UNIT |
Restart a service on a running system. |
systemctl restart UNIT |
Reload configuration file of a running service. |
systemctl reload UNIT |
Completely disable a service from being started, both manually and at boot. |
systemctl mask UNIT |
Make a masked service available. |
systemctl unmask UNIT |
Configure a service to start at boot time. |
systemctl enableUNIT |
Disable a service from starting at boot time. |
systemctl disable UNIT |
List units which are required and wanted by the specified unit. |
systemctl list- dependenciesUNIT |
|
|
Keywords indicating the state of the service
loaded |
Unit configuration file has been processed. |
active(running) |
Running with one or more continuing processes. |
active (exited) |
Successfully completed a one-time configuration. |
active (waiting) |
Running but waiting for an event. |
inactive |
Not running. |
enabled |
Will be started at boot time. |
disabled |
Will not be started at boot time. |
static |
Can not be enabled, but may be started by an enabled unit automatically |
Listing unit files with systemctl
1. Query the state of all units to verify a system startup.
[root@serverX ~]# systemctl
2. Query the state of only the service units.
[root@serverX ~]# systemctl --type=service
3. Investigate any units which are in a failed or maintenance state. -l option to full output.
[root@serverX ~]# systemctl status rngd.service -l
4. Alternate commands can also easily show the active and enabled states:
[root@serverX ~]# systemctl is-active/enabled sshd
5. List the active state of all loaded units.
[root@serverX ~]# systemctl list-units --type=service --all
6. View the enabled and disabled settings for all units.
[root@serverX ~]# systemctl list-unit-files --type=service
7. View only failed services.
[root@serverX ~]# systemctl --failed --type=service
|
|
|
Enabling system daemons to start or stop at boot
1. View the status of a service.
[root@serverX ~]# systemctl status sshd.service
2. Disable the service and verify the status. Note that disabling a service does not stop the service.
[root@serverX ~]# systemctl disable sshd.service
[root@serverX ~]# systemctl status sshd.service
3. Enable the service and verify the status.
[root@serverX ~]# systemctl enable sshd.service
[root@serverX ~]# systemctl is-enabled sshd.service
|
Starting and stopping system daemons
1. View the status of a service.
[root@serverX ~]# systemctl status sshd.service
2. Verify that the process is running.
[root@serverX ~]# ps -up PID
3. Stop the service and verify the status.
[root@serverX ~]# systemctl stop/status sshd.service
4. Start the service and view the status. The process ID has changed.
[root@serverX ~]# systemctl start/status sshd.service
5. Stop, then start, the service in a single command.
[root@serverX ~]# systemctl restart/status sshd.service
6. Issue instructions for a service to read and reload. The process ID will not change.
[root@serverX ~]# systemctl reload/status sshd.service
|
|
|
Identify the Status of systemd Units
1. List all service units on the system.
[student@serverX ~]$ sudo systemctl list-units --type=service
2. List all socket units, active and inactive, on the system.
[student@serverX ~]$ sudo systemctl list-units --type=socket --all
3. Explore the status of the chronyd service. This service is used for network time synchronization (NTP).
a. Display the status of the chronyd service. Note the process ID of any active daemons.
[student@serverX ~]$ sudo systemctl status chronyd
b. Confirm that the listed daemons are running.
[student@serverX ~]$ ps -p PID
4. Explore the status of the sshd service. This service is used for secure encrypted communication between systems.
a. Determine if the sshd service is enabled to start at system boot.
[student@serverX ~]$ sudo systemctl is-enabled sshd
b. Determine if the sshd service is active without displaying all of the status information.
[student@serverX ~]$ sudo systemctl is-active sshd
c. Display the status of the sshd service.
[student@serverX ~]$ sudo systemctl status sshd
5. List the enabled or disabled states of all service units.
[student@serverX ~]$ sudo systemctl list-unit-files --type=service
|
|