Using systemd to Manage Services on Linux

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

Checking the status of a service in systemd

Some definitions:

  • active = currently running
  • inactive = currently not running
  • enabled = set to start automatically at boot
  • disabled = will not start automatically at boot
  • vendor preset: enabled = by default, the service will start automatically at boot
  • vendor 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
The 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

The 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

Listing all services using systemctl

Exampe 2. Listing only active services (those that are currently running):

$ systemctl list-units --all --state=active

Listing only active services using systemctl

Example 3. Listing only inactive services (those that are installed but not running):

$ systemctl list-units --all --state=inactive

Listing only inactive services using systemctl

Leave a Comment

Your email address will not be published. Required fields are marked *