Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Controlling Services and Daemons

systemctl list-units --type=service

By default, the systemctl list-units --type=service command lists only the service units with active
activation states. The --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.

systemctl list-units --type=service --all

The systemctl command without any arguments lists units that are both loaded and active.

systemctl

The systemctl list-units command displays units that the systemd service attempts to parse
and load into memory; it does not display installed, but not enabled, services. To see the state
of all unit files installed, use the systemctl list-unit-files command. For example:

systemctl list-unit-files --type=service

systemctl status sshd.service

systemctl is-active sshd.service

Run the following command to verify whether a service unit is enabled to


start automatically during system boot:

systemctl is-enabled sshd.service

To verify whether the unit failed during startup, run the following command:

systemctl is-failed sshd.service

systemctl list-units --type=socket --all

systemctl status chronyd

ps -p 680

systemctl is-enabled ssh


systemctl is-active sshd
List the enabled or disabled states of all service units.

systemctl list-unit-files --type=service

Starting and Stopping Services

systemctl start sshd.service

The systemd service looks for .service files for service management in commands in the absence
of the service type with the service name. Thus the above command can be executed as:

systemctl start sshd

systemctl stop sshd.service

Restarting and Reloading Services

During a restart of a running service, the service is stopped and then started. On the restart of
service, the process ID changes and a new process ID gets associated during the startup.

systemctl restart sshd.service

Some services have the ability to reload their configuration files without requiring a restart. This
process is called a service reload. Reloading a service does not change the process ID associated with
various service processes.

systemctl reload sshd.service

systemctl reload-or-restart sshd.service

Listing Unit Dependencies

systemctl list-dependencies sshd.service

Masking and Unmasking Services

Masking a service prevents an administrator from accidentally starting a service that conflicts with
others. Masking creates a link in the configuration directories to the /dev/null file which prevents
the service from starting.

systemctl mask sendmail.service


systemctl start sendmail.service

Failed to start sendmail.service: Unit sendmail.service is masked.

systemctl unmask sendmail

Removed /etc/systemd/system/sendmail.service.

Enabling Services to Start or Stop at Boot

systemctl enable sshd.service

Created symlink /etc/systemd/system/multi-user.target.wants/sshd.service


→ /usr/lib/systemd/system/sshd.service.

systemctl disable sshd.service

Removed /etc/systemd/system/multi-user.target.wants/sshd.service.

Table 9.3. Useful Service Management Commands

Task Command
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 the configuration file of a running service. systemctl reload UNIT
Completely disable a service from being started, both
systemctl mask UNIT
manually and at boot.
Make a masked service available. systemctl unmask UNIT
Configure a service to start at boot time. systemctl enable UNIT
Disable a service from starting at boot time. systemctl disable UNIT
List units required and wanted by the specified unit. systemctl list-dependencies
UNIT

Reboot servera, then view the status of the chronyd service.

[student@servera ~]$ sudo systemctl reboot


ssh student@servera
systemctl status chronyd

You might also like