How to Start, Stop & Restart Services in Ubuntu

In Linux, there are a variety of services running in the background, which may be known as Damons. These services can be managed by different command utilities. For example, the Apache web server can be managed by running, restarting, stopping, or displaying its version. For these types of functionalities, different ways are used.

In this write-up, different ways to start, stop, and restart the services in Ubuntu will be explained. This article’s content is as follows:

How to Start, Stop, and Restart the Services in Ubuntu?

Several methods are followed to start, restart & stop services in Ubuntu. In this article, we will demonstrate the usage of three command line utilities (systemctl, service, init) to manage Ubuntu services.

Note: As an example, we will consider the “ufw” service and show how it can be managed.

Let’s start now!

Method 1: Using systemctl Command

The most-used command for starting, stopping, restarting, or checking the status of the services in Ubuntu is “systemctl”. This command utility allows us to perform management tasks using the Service Manager.

The systemctl command syntax is given below:

$ sudo systemctl start <service>         #to start the services
$ sudo systemctl stop <service>          #to stop the services
$ sudo systemctl restart <service>       #to restart the services
$ sudo systemctl status <service>        #to check the status of the service

Starting the Service Using systemctl Command

To start the service named “ufw” in Ubuntu, use the below-written command:

$ sudo systemctl start ufw
$ sudo systemctl status ufw

The “active” status of the “ufw” service verifies the start of the service.

Stopping the Service Using systemctl Command

To stop the service, utilize the “systemctl” command below:

$ sudo systemctl stop ufw

Restarting the Service Using systemctl Command

The “systemctl” command can be used to restart the “ufw” service by executing the below command:

$ sudo systemctl restart ufw

Method 2: Using service Command

The service command is used to perform different tasks like start, stop and restart. Let’s perform different functions with the service command.

The service commands syntax is shown below:

$ sudo service <service> start            #to start the service
$ sudo service <service> stop            #to stop the service
$ sudo service <service> restart         #to restart the service
$ <service> –status-all                        #to check the status of the service

The below “service” command shows all services with their status as

$ service --status-all

The output is described below:

  • [ + ] shows the services are “Enabled
  • [ – ] shows the services are “Disabled

Starting a Service Using service Command

The general syntax of starting the desired service the general syntax of the command is “service <service-name> start”. To start the uncomplicated firewall (ufw) services, utilize the “service” commands with their status as follows:

$ sudo service ufw start
$ sudo service ufw status

Stopping a Service Using service Command

To stop a service, use the general syntax “service <service-name> stop,” and to stop the “ufw” service, execute the below command in the terminal:

$ sudo service ufw stop

Restarting a Service Using service Command

The “sudo service <service-name> restart” command is used for restarting a service. The “ufw” cab be restarted utilizing the below-mentioned command:

$ sudo service ufw restart

Method 3: Using init Command

The “init” command uses the “/etc/init.d” directory to execute the start, stop & restart services. Let’s use the “init” command.

The general syntax of the init command utilities is provided below:

$ sudo /etc/init.d/<service> start           #to start the service
$ sudo /etc/init.d/<service> stop             #to stop the service
$ sudo /etc/init.d/<service> restart         #to restart the service
$ <service> –status-all                  #to check the status of the service

Starting the Service Using init Command

Use the below-written command to start the “ufw” service:

$ sudo /etc/init.d/ufw start

Stopping the Service Using init Command

To stop the service of the “ufw” firewall in a system, execute the following command in the terminal:

 $ sudo /etc/init.d/ufw stop

Restarting the Service Using init Command

To restart the service “ufw” in Ubuntu can be performed by running the below-mentioned command in the terminal:

$ sudo /etc/init.d/ufw restart

Bonus-Tip: Checking All & Only Running Services on Ubuntu

For check the system’s available services, use the “systemctl” command as given below:

$ systemctl list-unit-files --type service -all

The output is showing the service name, the “state” of the service and predetermined value of the service.

To limit the services to running services on the system, we can use the “grep” with systemctl command as shown below:

$ sudo systemctl | grep running

The running services on the system are shown in the output.

That’s all from this post!

Conclusion

To restart, start & stop services in Ubuntu, use the “systemctl”, “service”, and “init” command line utilities. All these command line utilities offer effective commands to manage the services. This post shows a detailed explanation of all these commands to start/stop/restart services on Ubuntu. Apart from that, we have also provided the method to list down the services (either running or all) on Ubuntu.