Systemctl Commands - Manage Systemd Services

Learn essential systemctl commands to manage systemd services. Start, stop, restart, enable, disable, and check the status of services on Linux systems.

Systemctl Commands

The systemctl command is the primary tool for controlling the systemd system and service manager. It allows administrators to manage services, units, and the overall system state on modern Linux distributions.

Systemd Service Management

Managing services is a core function of systemctl. You can start, stop, restart, and check the status of individual services.

# Start, stop, or restart a given service(s).
systemctl [start|stop|restart] [SERVICE]

# Show the current status of a given service(s).
systemctl status [SERVICE]

Checking Service Status and State

Determine if a service is running, enabled, or has encountered failures.

# Check if a given service(s) is active. If it is, 'active' will display. An
# exit status of 0 will be given if it's active, and non-zero otherwise. Use
# the `-q` or `--quiet` flag to rely only on the exit status.
systemctl is-active ufw

# Check if a given service(s) has failed. If it is, 'failed' will display. An
# exit status of 0 will be given if it has failed, and non-zero otherwise. Use
# the `-q` or `--quiet` flag to rely only on the exit status.
systemctl is-failed ufw

# Check if a given service(s) is enabled. If it is, 'enabled' will display. An
# exit status of 0 will be given if it's enabled, and non-zero otherwise. Use
# the `-q` or `--quiet` flag to rely only on the exit status.
systemctl is-enabled ufw

# List all failed services.
systemctl --failed

Enabling and Disabling Services

Control whether services start automatically at boot time.

# Enable or disable a given service(s).
systemctl [enable|disable] [SERVICE]

System Power Management

Control the system's power state, including shutting down or rebooting.

# Shut the system down. Use `suspend` to suspend, `halt` to halt, and `reboot`
# to instead of reboot the machine.
systemctl poweroff

Retrieving Specific Service Information

Extract specific configuration values from service units for scripting or detailed analysis.

# Show only a given value from one of the `show` keys. In this example, the
# value for the `ActiveState` key for the UFW service will be shown, and only
# it; ideal for scripting.
#
# Using the `--value` flag causes only the value to be displayed.
systemctl show -p ActiveState --value ufw

Further Reading

For more in-depth information on systemd and systemctl, refer to the official documentation: