Services are important background processes on a system. Generally, they are launched when you boot up your system. If you are just a regular desktop user, knowing how to start, stop and restart services is essential for various day to day tasks. On the other hand, managing services is a common job for a Linux system admin. In this tutorial, we will discuss how to start, stop and restart services on a Linux system.
Note: This tutorial was made with an Ubuntu 18.04 running system. However, the same instructions will work on Ubuntu 16.04 and Debian-based distributions like Elementary OS, Linux Mint, and Debian.
Getting started
There are two common methods used when we discuss how to start, stop, and restart services on Linux. These two methods are systemd and init. Both init and systemd are daemon processes designed to manage services on a Linux system and are launched when the system is booted up. While init is an abbreviation for ‘initialization’, systemd is a system management daemon which has a ‘d’ at the end to follow the UNIX naming convention for daemons.
The systemd daemon provides us with the systemctl command to work with system services. The name systemctl is an abbreviation for ‘system control. The service command is used to
Using the service command
The service command is part of the init daemon. It was used commonly in earlier distributions of Linux based systems to manage services on a system. Let us have a look at how to start, stop and restart services using the service command.
1. Listing all the services
Before we learn how to start, stop and restart services on Linux using the service command, we need to know how to list all the services using the init daemon. To do so, we use the following command.
service --status -all
Using this command in the command line will give an output similar to the one seen below. Notice that we get a list of all the services on our system. In this list, services preceded by a [+] sign are enabled while the ones preceded by a [-] sign are disabled.
This command can be used to find out the current status of a service on our system. Otherwise, you can use it to verify that your signal to the system to start, stop or restart a service took effect.
2. Starting a service
Now we will discuss how to start a service. To do so, we use the start option of the service command. This option is preceded by the name of the service which we wish to start. We type the following command to stop a service on a Linux system.
service <ServiceName> start
3. Stopping a service
To stop a service using the service command, we utilise the stop option. This option is preceded by the name of the service which we wish to stop. Typing the following command will stop the specified service on your Linux system.
service <ServiceName> stop
4. Restarting a service
To restart a service using the service command, we make use of the restart option. Like previous examples, this option is typed after the name of the service which we wish to start. The following command helps us restart a service on Linux.
service <ServiceName> restart
Using the systemctl command
The systemctl command is part of the systemd daemon. It is used commonly in newer distributions of Linux based systems to manage services on a system. The systemd daemon was designed to replace the init daemon by offering better service management efficiency. Let us have a look at how to start, stop and restart services using the systemctl command.
1. Listing all the services
Before we have a look at how to start, stop and restart services on Linux using the systemctl command, we need to know how to list all the services using the systemd daemon. To do so, we type the following command in our terminal.
systemctl list-unit-files --type service -all
Using the systemctl command will give an output similar to the one seen below. Notice that we get a list of all the services on our system. In this list, unlike the symbolic representation seen in case of the services command, we get a new column that holds the status of the services on our system.
This command can be used to find out the current status of a service on our system. Else, you can use it to verify that your signal to the system to start, stop or restart a service took effect.
2. Starting a service
To start a service using the systemctl command, we utilise the start option. This option is followed by the name of the service which we wish to start. Type the following command to start a service on your Linux system.
systemctl start <ServiceName>
3. Stopping a service
Now we will discuss how to stop a service. To do so, we use the stop option of the systemctl command. This option is followed by the name of the service which we wish to start. We use the following command to stop a service on a Linux system.
systemctl stop <ServiceName>
4. Restarting a service
To restart a service using the systemctl command, we utilise the restart option. Like previous examples, this option is followed by the name of the service which we wish to start. The following command helps us restart a service on Linux.
systemctl restart <ServiceName>
FAQ’s
How can I start a service in Linux?
You can start a service in Linux by using the command “systemctl start [service name]”.
What is systemd in Linux?
Systemd is a system and service manager for Linux, which is designed to start and manage system processes and services, including the management of dependencies between services.
How do I stop a service in Linux?
You can stop a service in Linux by using the command “systemctl stop [service name]”.
How do I enable a service in Linux?
To enable a service in Linux so that it starts on boot, you can use the command “systemctl enable [service name]”.
How do I disable a service in Linux?
You can disable a service in Linux using the command “systemctl disable [service name]”.
What is a service in Linux?
A service in Linux refers to a program or process that runs in the background and can be controlled or managed by the system administrator. It could be a network service, such as a web server, or a system service, such as a logging service.
What is the command to restart a service in Linux?
The command to restart a service in Linux is “sudo systemctl restart [servicename]”. Replace [servicename] with the name of the service you want to restart.
Conclusion
All Linux users need to know how to start, stop and restart services. This enables a person to have greater control over the services on their system. Knowing service management is also helpful while installing new utilities or programs like a server on your machine.
This is because new services often need to be manually started, while old services need to be restarted in case of configuration changes. We hope this tutorial was able to help you understand the process to start, stop, and restart services on a Linux system. If you have any feedback, queries, or suggestions, feel free to reach out to us in the comments below.