The majority of Linux distributions rely on Systemd to manage all of the daemons and services running on a system. Systemd allows users to manage and administer system services, mainly through use of the systemctl
command. In this tutorial, you will learn how to use systemd to manage and interact with services on Linux.
Check Status of a Service
Checking the status will tell you if a service is active, inactive, enabled, or disabled. It will also show recent log information, including errors if there are any. Other information includes the PID and how long the service has been running for.
$ systemctl status service_name
Some definitions:
active
= currently runninginactive
= currently not runningenabled
= set to start automatically at bootdisabled
= will not start automatically at bootvendor preset: enabled
= by default, the service will start automatically at bootvendor preset: disabled
= by default, the service won’t start automatically at boot
Start, Stop, and Restart a Service
Example 1. Starting a service:
$ sudo systemctl start service_name
Example 2. Stopping a service:
$ sudo systemctl stop service_name
Example 3. Restarting a service:
$ sudo systemctl restart service_name
reload
option will reload a service’s configuration files (in case of changes), whereas the restart
option will completely restart the service.Example 4. Reloading a service:
$ sudo systemctl reload service_name
Enable and Disable a Service
enable
option will make a service start automatically whenever the system boots up. The disable
option will prevent it from starting up automatically.Example 1. Enabling a service:
$ sudo systemctl enable service_name
Example 2. Disabling a service:
$ sudo systemctl disable service_name
Listing Services in Systemd
Example 1. Listing all services:
$ systemctl list-units --all --type=service --no-pager
Exampe 2. Listing only active services (those that are currently running):
$ systemctl list-units --all --state=active
Example 3. Listing only inactive services (those that are installed but not running):
$ systemctl list-units --all --state=inactive