How to restart a service via systemctl under Linux

A service is a background process that starts automatically when the system boots. For ordinary users, and especially for system administrators, restarting a service is a common system administration task that often needs to be performed when adjusting system settings or installing a new application.

In this article, we will learn how to restart a service via systemctl in Linux. Systemctl is basically a command line system application that is used to manage system services and allows you to start, stop, restart, enable, disable, and view the status of services.

We used Debian 10 to execute the commands and procedures mentioned in this article, but the same commands will work on other distributions such as Ubuntu, CentOS or Fedora.

Restarting a service using Systemctl

The command line terminal is used to restart the service. To open Terminal, go to the Actions tab in the upper left corner of your desktop. Then, in the search menu that appears, find the Terminal application and launch it.

To list all enabled services on your system, run the following command in Terminal:

$ systemctl list-unit-files | grep enabled

From the list above, you can find out the exact name of the service you want to restart using the systemctl command.

To restart a running service (stop and then start) use the following command syntax in Terminal:

$ sudo systemctl restart [service-name]

For example, to restart the xrdp service, replace the “service-name” parameter with the exact name of the service.

Restart the service using systemctl

Managing Services with Systemd

Along with restarting the service, you can also control the service using the systemctl command, such as starting, stopping, enabling, disabling, and viewing the status of the service.

To view the current status of a service, whether it is running or not, use the following command syntax in Terminal:

$ systemctl status [service-name]

Use the following syntax to start the service:

$ systemctl start [service-name]

To stop a running service, use the following syntax:

$ systemctl stop [service-name]

To enable the service to start automatically at boot, use the following syntax:

$ systemctl enable [service-name]

To disable automatic starting of a service on boot, use the following syntax:

$ systemctl disable [service-name]

To reload the service, use the following syntax:

$ systemctl reload [service-name]

To reboot or restart the service (it reloads the service and if no restart is available, it restarts the service).

$ sudo systemctl reload-or-restart [service-name]

To check if a service is active:

$ sudo systemctl is-active [service-name]

To check if a service is enabled to start automatically at system boot:

$ sudo systemctl is-enabled [service-name]

In this article, we learned how to restart a service using the systemctl command. We also learned about another common use of the systemctl command to manage services.

How to restart a service via systemctl under Linux

Sidebar