RHCSA Rapid Track
- Section Identify Automatically Started System Processes
- Guided Exercise: Identify Automatically Started System Processes
- Control System Services
- Guided Exercise: Control System Services
- Select the Boot Target
- Guided Exercise: Select the Boot Target
- Reset the Root Password
- Guided Exercise: Reset the Root Password
- Repair File-system Issues at Boot
- Guided Exercise: Repair File-system Issues at Boot
- Lab: Control the Boot Process
- Summary
Abstract
| Goal |
Control and monitor network services, system daemons, and the boot process by using systemd services. |
| Objectives |
|
| Sections |
|
| Lab |
|
List system daemons and network services that were started by the
systemdservice and socket units.
The systemd daemon manages the startup process for Linux, including service startup and service management in general. The systemd daemon activates system resources, server daemons, and other processes, both at boot time and on a running system.
Daemons are processes that either wait or run in the background, to perform various tasks. Generally, daemons start automatically at boot time and continue to run until shutdown or until you manually stop them. By convention, daemon names end with d.
A service in the systemd sense often refers to one or more daemons. However, starting or stopping a service might instead change the state of the system once, without leaving a running daemon process afterward (called oneshot).
In Red Hat Enterprise Linux, the first process that starts (PID 1) is the systemd daemon, which provides these features:
Parallelization capabilities (starting multiple services simultaneously), which increase the boot speed of a system.
On-demand starting of daemons without requiring a separate service.
Automatic service dependency management, which can prevent long timeouts. For example, a network-dependent service does not try to start until the network is available.
A method of tracking related processes together by using Linux control groups.
A systemd
unit is an abstract concept to define objects that the system knows how to manage.
Units are represented by configuration files called unit files, which encapsulate information about system services, listening sockets, and other relevant objects for the systemd init system.
A unit has a name and a unit type. The name provides a unique identity to the unit. The unit type enables grouping units together with other similar unit types.
The systemd daemon uses units to manage different types of objects:
Service units have a
.serviceextension and represent system services. You can use service units to start often-accessed daemons, such as a web server.Socket units have a
.socketextension and represent inter-process communication (IPC) sockets thatsystemdshould monitor. If a client connects to the socket, then thesystemdmanager starts a daemon and passes the connection to it. You can use socket units to delay the start of a service at boot time and to start less often used services on demand.Path units have a
.pathextension and delay the activation of a service until a specific file-system change occurs. You can use path units for services that use spool directories, such as a printing system.
To manage units, use the systemctl command. For example, display available unit types with the systemctl -t help command. The systemctl command can take abbreviated unit names, process tree entries, and unit descriptions.
Use the systemctl command to explore the system's current state. For example, the following command lists and paginates all currently loaded service units.
[root@host ~]# systemctl list-units --type=service
UNIT LOAD ACTIVE SUB DESCRIPTION
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing Service
chronyd.service loaded active running NTP client/server
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
...output omitted...In this example, the --type=service option limits the type of systemd units to service units. The output has the following columns:
-
UNIT The service unit name.
-
LOAD Whether the
systemddaemon correctly parsed the unit's configuration and loaded the unit into memory.-
ACTIVE The high-level activation state of the unit. This information indicates whether the unit started successfully.
-
SUB The low-level activation state of the unit. This information indicates more detailed information about the unit. The information varies based on unit type, state, and how the unit is executed.
-
DESCRIPTION The short description of the unit.
By default, the systemctl list-units --type=service command lists only the service units with active activation states. The systemctl list-units --all option lists all service units regardless of the activation states. Use the --state= option to filter by the values in the LOAD, ACTIVE, or SUB fields.
[root@host ~]# systemctl list-units --type=service --all
UNIT LOAD ACTIVE SUB DESCRIPTION
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing ...
auth-rpcgss-module.service loaded inactive dead Kernel Module ...
chronyd.service loaded active running NTP client/server
cpupower.service loaded inactive dead Configure CPU power ...
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
● display-manager.service not-found inactive dead display-manager.service
...output omitted...The systemctl command without any arguments lists units that are both loaded and active.
[root@host ~]# systemctl
UNIT LOAD ACTIVE SUB DESCRIPTION
proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary...
sys-devices-....device loaded active plugged Virtio network...
sys-subsystem-net-devices-ens3.deviceloaded active plugged Virtio network...
...output omitted...
-.mount loaded active mounted Root Mount
boot.mount loaded active mounted /boot
...output omitted...
systemd-ask-password-plymouth.path loaded active waiting Forward Password...
systemd-ask-password-wall.path loaded active waiting Forward Password...
init.scope loaded active running System and Servi...
session-1.scope loaded active running Session 1 of...
atd.service loaded active running Job spooling tools
auditd.service loaded active running Security Auditing...
chronyd.service loaded active running NTP client/server
crond.service loaded active running Command Scheduler
...output omitted...The systemctl command list-units option displays units that the systemd service attempts to parse and load into memory. This option does not display services that are installed but not enabled. You can use the systemctl command list-unit-files option to see the state of all the installed unit files:
[root@host ~]# systemctl list-unit-files --type=service
UNIT FILE STATE VENDOR PRESET
arp-ethers.service disabled disabled
atd.service enabled enabled
auditd.service enabled enabled
auth-rpcgss-module.service static -
autovt@.service alias -
blk-availability.service disabled disabled
...output omitted...In the output of the systemctl list-unit-files command, some common entries for the STATE field are enabled, disabled, static, and masked. All STATE values are listed in the systemctl command manual pages.
View a unit's status with the systemctl status command. If the unit type is omitted, then the command expects a service unit with that name.name.type
[root@host ~]# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-03-14 05:38:12 EDT; 25min ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1114 (sshd)
Tasks: 1 (limit: 35578)
Memory: 5.2M
CPU: 64ms
CGroup: /system.slice/sshd.service
└─1114 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Mar 14 05:38:12 workstation systemd[1]: Starting OpenSSH server daemon...
Mar 14 05:38:12 workstation sshd[1114]: Server listening on 0.0.0.0 port 22.
Mar 14 05:38:12 workstation sshd[1114]: Server listening on :: port 22.
Mar 14 05:38:12 workstation systemd[1]: Started OpenSSH server daemon.
...output omitted...Some fields from the systemctl command status option output:
Table 11.1. Service Unit Information
| Field | Description |
|---|---|
| Loaded | Whether the service unit is loaded into memory |
| Active | Whether the service unit is running, and if so, for how long |
| Docs | Where to find more information about the service |
| Main PID | The main process ID of the service, including the command name |
| Status | More information about the service |
| Process | More information about related processes |
| CGroup | More information about related control groups |
Not all these fields are always present in the command output.
Keywords in the status output indicate the state of the service:
Table 11.2. Service States in the Output of systemctl
| Keyword | Description |
|---|---|
| loaded | The unit configuration file is processed. |
| active (running) | The service is running with continuing processes. |
| active (exited) | The service successfully completed a one-time configuration. |
| active (waiting) | The service is running but is waiting for an event. |
| inactive | The service is not running. |
| enabled | The service starts at boot time. |
| disabled | The service is not set to start at boot time. |
| static | The service cannot be enabled, but an enabled unit might start it automatically. |
Note
The systemctl status command replaces the NAMEservice command from Red Hat Enterprise Linux 6 and earlier versions.NAME status
The systemctl command verifies the specific states of a service. For example, use the systemctl command is-active option to verify whether a service unit is active (running):
[root@host ~]# systemctl is-active sshd.service
activeThe command returns the service unit state, which is usually active or inactive.
Run the systemctl command is-enabled option to verify whether a service unit is enabled to start automatically during system boot:
[root@host ~]# systemctl is-enabled sshd.service
enabledThe command returns whether the service unit is enabled to start at boot time, and the state is usually enabled or disabled.
To verify whether the unit failed during startup, run the systemctl command is-failed option:
[root@host ~]# systemctl is-failed sshd.service
activeThe command returns active if the service is correctly running, or failed if an error occurred during startup. If the unit was stopped, then it returns unknown or inactive.
To list all the failed units, run the systemctl --failed --type=service command.
References
systemd(1), systemd.unit(5), systemd.service(5), systemd.socket(5), and systemctl(1) man pages
For more information, refer to the Managing Services with systemd chapter in the Red Hat Enterprise Linux 9 Configuring Basic System Settings Guide at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/configuring_basic_system_settings/managing-services-with-systemd_configuring-basic-system-settings#managing-services-with-systemd_configuring-basic-system-settings