Chapter 2. Managing system services with systemctl
To administer system level services, use the systemctl utility. You can interact with systemd by enabling control of services and units. With systemctl, you can manage states of system services, list available services, and display status of system services.
2.1. Listing system services リンクのコピーリンクがクリップボードにコピーされました!
To optimize system performance, you can use the systemctl command to list and review system services. System services handle background processes, manage hardware, and supports core system functionality.
Prerequisites
- You have administrative privileges.
Procedure
List all currently loaded service units:
systemctl list-units --type service
$ systemctl list-units --type serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow By default, the
systemctl list-unitscommand displays only active units. For each service unit file, the command provides an overview of the following parameters:UNIT- The full name of the service unit
LOAD- The load state of the configuration file
ACTIVEorSUB- The current high-level and low-level unit file activation state
DESCRIPTION- A short description of the unit’s purpose and functionality
List all loaded units regardless of their state:
systemctl list-units --type service --all
$ systemctl list-units --type service --allCopy to Clipboard Copied! Toggle word wrap Toggle overflow List the status, for example
enabledordisabled, of all available service units:systemctl list-unit-files --type service
$ systemctl list-unit-files --type serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow For each service unit, this command displays:
-
UNIT FILE: The full name of the service unit -
STATE: The information whether the service unit is enabled or disabled to start automatically during boot
-
2.2. Displaying system service status リンクのコピーリンクがクリップボードにコピーされました!
To inspect any service unit to get detailed information and verify the state of the service, use the systemctl command. Status information includes whether the service unit is running, enabled to start during boot, or masked.
You can also view services that are scheduled to start after or before a particular service unit. See the following table for the available service unit information.
| Field | Description |
|---|---|
|
| Information whether the service unit has been loaded, the absolute path to the unit file, and a note whether the unit is enabled to start during boot. |
|
| Information whether the service unit is running followed by a timestamp. |
|
| The process ID and the name of the corresponding system service. |
|
| Additional information about the corresponding system service. |
|
| Additional information about related processes. |
|
|
Additional information about related control groups ( |
You can use the following commands to display system service status:
Display detailed information about a service unit that corresponds to a system service:
systemctl status <name>.service
$ systemctl status <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace <name> with the name of the service unit you want to inspect, for example,
gdm.This command displays the following information:
- The name of the selected service unit followed by a short description
-
The execution of the service unit, if the unit is executed by the
rootuser - The most recent log entries
- Detailed information about the service unit
Verify that a particular service unit is running:
systemctl is-active <name>.service
$ systemctl is-active <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Decide whether a particular service unit is enabled to start during boot time:
systemctl is-enabled <name>.service
$ systemctl is-enabled <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Both
systemctl is-activeandsystemctl is-enabledcommands return an exit status of0if the specified service unit is running or enabled.Check which services systemd scheduled to start before the specified service unit:
systemctl list-dependencies --after <name>.service
# systemctl list-dependencies --after <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to view the list of services ordered to start before
gdm, enter:systemctl list-dependencies --after gdm.service
# systemctl list-dependencies --after gdm.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check what services systemd orders to start after the specified service unit:
systemctl list-dependencies --before <name>.service
# systemctl list-dependencies --before <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to view the list of services systemd orders to start after
gdm, enter:systemctl list-dependencies --before gdm.service
# systemctl list-dependencies --before gdm.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.3. Starting and stopping a systemd unit リンクのコピーリンクがクリップボードにコピーされました!
To start or stop a system service in the current session, you can use the systemctl command.
Prerequisites
- You have administrative privileges.
Procedure
To start or stop a system service:
systemctl <action> <systemd_unit>
# systemctl <action> <systemd_unit>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace <action> with the action you want to perform to enable or disable the service, for example,
startorstop, and replace <systemd_unit> with the service unit name, for example,httpd.NoteStarting a particular service might require starting one or more other services (positive dependency) or stopping one or more services (negative dependency). In systemd, positive and negative dependencies between services exist.
When you try to start a new service, systemd resolves all dependencies automatically, without explicit notification to the user. This means that if you are already running a service, and you try to start another service with a negative dependency, the first service is automatically stopped.
For example, if you are running the
httpdservice (Apache web server) and then try to start the NGINX service, systemd will automatically stop httpd first. This is because both services are web servers that cannot run simultaneously on the same port (usually port 80 or 443).
2.4. Restarting and reloading a system service リンクのコピーリンクがクリップボードにコピーされました!
To restart or reload a system service in the current session, use the systemctl command. You can use this command to stop the selected service unit and start it again, restart if service is already running, or reload the service without interrupting its execution.
Prerequisites
- You have administrative privileges.
Procedure
Restart a system service:
systemctl restart <name>.service
# systemctl restart <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<name>with the name of the service unit you want to restart (for example,httpd).Restart a service unit only if the corresponding service is already running:
systemctl try-restart <name>.service
# systemctl try-restart <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the configuration without interrupting service execution:
systemctl reload <name>.service
# systemctl reload <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Certain services do not support reload operations. If you use
systemctl reload-or-restartorsystemctl reload-or-try-restart, systemd automatically restarts the service if a reload is not possible. Note that a restart of a service might interrupt connections to this service.For details, see
systemctl(1)man page on your system.
2.5. Enabling a system service to start at boot リンクのコピーリンクがクリップボードにコピーされました!
To enable a service to start automatically at boot, you can use the systemctl command. These changes apply with the next reboot.
Prerequisites
- You have administrative privileges.
Procedure
Check if the unit is masked:
systemctl status <systemd_unit>
# systemctl status <systemd_unit>Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the unit is masked, unmask it first:
systemctl unmask <systemd_unit>
# systemctl unmask <systemd_unit>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable a service to start at boot time:
systemctl enable --now <systemd_unit>
# systemctl enable --now <systemd_unit>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<systemd_unit>with the name of the service unit you want to enable, for example,httpd.
2.6. Disabling a system service to start at boot リンクのコピーリンクがクリップボードにコピーされました!
To reduce boot time of your system, you need to either disable or mask the services that start automatically at boot time.
If you disable a service, it will not start at boot, but you can start it manually.
To prevent a service unit from starting automatically or manually, you can mask the service. Masking is a way of disabling a service that makes the service permanently unusable until it is unmasked again.
Prerequisites
- You have administrative privileges.
Procedure
Disable a service to start at boot:
systemctl disable <name>.service
# systemctl disable <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<name>with the name of the service unit you want to disable (for example,bluetooth). Optionally, pass the--nowcommand to also stop the service if it is currently running.To prevent the unit from being accidentally started by an administrator or as a dependency of other units, mask the service:
systemctl mask <name>.service
# systemctl mask <name>.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow For details, see the
systemctl(1)man page on your system.