A service is a background process that automatically runs when you boot up your system. For regular users and especially system administrators, restarting a service is a common system administration task that you often have to perform while configuring system settings or installing a new application.
In this article, we will learn about how to restart a service through systemctl on Linux. Systemctl is basically a command-line system application that is used to manage the system services and allows to start, stop, restart, enable, disable, and view the status of the services.
We have used Debian 10 for running the commands and procedures mentioned in this article, but the same commands will work on other Distributions like Ubuntu, CentOS or Fedora too.
Restarting a Service with Systemctl
To restart a service, command-line Terminal is used. In order to open the Terminal, go to the Activities tab in the top left corner of your desktop. Then from the search menu that appears, search for the Terminal application and launch it.
To list all enable services on your system, run the following command in Terminal:
$ systemctl list-unit-files | grep enabled
From the above list, you can find out the exact name of the service you want to restart using the systemctl command.
In order to restart a running service(Stop and then start), use the following command syntax in Terminal:
$ sudo systemctl restart [service-name]
For instance, to restart the xrdp service, replace the “service-name” parameter with the exact name of the service.
Manage Services with Systemd
Along with service restart, you can also manage service using systemctl command such as start, stop, enable, disable, and viewing the status of service.
In order to view the current status of the service whether it is running or not, use the following command syntax in Terminal:
$ systemctl status [service-name]
In order to start a service, use the following syntax:
$ systemctl start [service-name]
In order to stop a running service, use the following syntax:
$ systemctl stop [service-name]
In order to enable a service to automatically start on boot, use the following syntax:
$ systemctl enable [service-name]
In order to disable service to not automatically start on boot, use the following syntax:
$ systemctl disable [service-name]
In order to reload a service, use the following syntax:
$ systemctl reload [service-name]
In order to reload-or-restart a service (It reloads a service and in case, if reload is not available then it restarts the service.)
$ sudo systemctl reload-or-restart [service-name]
In order to check if service is active:
$ sudo systemctl is-active [service-name]
In order to check if service is enabled to automatically start on a system boot:
$ sudo systemctl is-enabled [service-name]
In this article, we have learned how to restart a service through the systemctl command. We also learned other common use of systemctl command for managing the services.