Introduction
Welcome to this guide on how to start, stop, and restart services in Linux. Linux is a powerful operating system that can be used to manage a variety of services. In this guide, we will discuss how to start, stop, and restart services in Linux. We will also discuss the different commands used to manage services in Linux. By the end of this guide, you will have a better understanding of how to manage services in Linux.
How to Start, Stop, and Restart Services in Linux
1. Start a Service:
To start a service in Linux, use the command “service
2. Stop a Service:
To stop a service in Linux, use the command “service
3. Restart a Service:
To restart a service in Linux, use the command “service
Introduction
Linux provides fine-grained control over system services through systemd, using the systemctl command. Services can be turned on, turned off, restarted, reloaded, or even enabled or disabled at boot. If you are running Debian 7, CentOS 7, or Ubuntu 15.04 (or later), your system likely uses systemd.
This guide will show you how to use basic commands to start, stop, and restart services in Linux.
Prerequisites
- Access to a user account with sudo or root privileges
- Access to a terminal/command line
- The systemctl tool, included in Linux
Basic Syntax of systemctl Command
The basic syntax for using the systemctl command is:
systemctl [command] [service_name]
Typically, you’ll need to run this as a superuser with each command starting with sudo
.
How To Check If a Service is Running on Linux
To verify whether a service is active or not, run this command:
sudo systemctl status apache2
Replace apache2 with the desired service. In our case, we checked the status of Apache. The output shows that the service is active (running), as in the image below:
How to Restart a Service
To stop and restart the service in Linux, use the command:
sudo systemctl restart SERVICE_NAME
After this point, your service should be up and running again. You can verify the state with the status
command.
To restart Apache server use:
sudo systemctl restart apache2
How to Reload a Service
To force the service to reload its configuration files, type in the following command in the terminal:
sudo systemctl reload SERVICE_NAME
After reloading, the service is going to be up and running. Check its state with the status
command to confirm.
In our example, we reloaded Apache using:
sudo systemctl reload apache2
How to Start a Service
To start a service in Linux manually, type in the following in the terminal:
sudo systemctl start SERVICE_NAME
For instance, the command to start the Apache service is:
sudo systemctl start apache2
How to Stop a Service
To stop an active service in Linux, use the following command:
sudo systemctl stop SERVICE_NAME
If the service you want to stop is Apache, the command is:
sudo systemctl stop apache2
Check whether the service stopped running with the status
command. The output should show the service is inactive (dead).
How to Enable the Service at Boot
To configure a service to start when the system boots, use the command:
sudo systemctl enable SERVICE_NAME
To enable Apache upon booting the system, run the command:
sudo systemctl enable apache2
How to Disable Service at Boot
You can prevent the service from starting at boot with the command:
sudo systemctl disable SERVICE_NAME
For example:
sudo systemctl disable apache2
Variations in Service Names
If you work within the same Linux environment, you will learn the names of the services you commonly use.
For example, if you are building a website, you will most likely use systemctl restart apache2
frequently, as you refresh configuration changes to your server.
However, when you move between different Linux variants, it is helpful to know that the same service may have different names in different distributions.
For example, in Ubuntu and other Debian based distributions, the Apache service is named apache2. In CentOS 7 and other RedHat distros, the Apache service is called httpd or httpd.service.
Conclusion
In most modern Linux operating systems, managing a service is quite simple using the commands presented here.
Make sure to know the name of the service for the operating system you are using, and the commands in this article should always work.
How to Start, Stop, and Restart Services in Linux
Linux is a powerful operating system that can be used for a variety of tasks. One of the most common tasks is managing services, which are programs that run in the background and provide certain functionality. In this article, we will discuss how to start, stop, and restart services in Linux.
Starting Services
To start a service in Linux, you can use the systemctl
command. This command is used to manage system services and daemons. To start a service, you can use the start
subcommand. For example, to start the Apache web server, you can use the following command:
sudo systemctl start apache2
This command will start the Apache web server. You can also use the enable
subcommand to make sure that the service is started automatically when the system boots up.
Stopping Services
To stop a service in Linux, you can use the stop
subcommand. For example, to stop the Apache web server, you can use the following command:
sudo systemctl stop apache2
This command will stop the Apache web server. You can also use the disable
subcommand to make sure that the service is not started automatically when the system boots up.
Restarting Services
To restart a service in Linux, you can use the restart
subcommand. For example, to restart the Apache web server, you can use the following command:
sudo systemctl restart apache2
This command will restart the Apache web server. This is useful if you have made changes to the configuration of the service and need to apply them.
Conclusion
In this article, we discussed how to start, stop, and restart services in Linux. We used the systemctl
command to manage system services and daemons. We also discussed the start
, stop
, and restart
subcommands, which can be used to start, stop, and restart services, respectively.