How to Restart Services in Linux: 5 Steps

Table of contents:

How to Restart Services in Linux: 5 Steps
How to Restart Services in Linux: 5 Steps
Anonim

This article explains how to force restart services currently running on a Linux system. You can do this with a few simple commands, regardless of the version of Linux you are using.

Steps

Restart Services in Linux Step 1
Restart Services in Linux Step 1

Step 1. Log in to the command line

Most Linux distributions present a Menu of options located in the lower left corner of the desktop. Within this menu there is an application called "Terminal" which allows you to execute commands at the operating system level.

  • Since Linux distributions vary from version to version, the "Terminal" app or the one corresponding to the command console may be stored inside the folder Menu.
  • In some cases the "Terminal" app may be placed directly on the desktop or on the toolbar docked at the bottom of the screen.
  • Some Linux distributions provide the command line directly at the top or bottom of the desktop.
Restart Services in Linux Step 2
Restart Services in Linux Step 2

Step 2. Run the command which shows the list of all currently active services

Type the code ls /etc/init.d into the "Terminal" window and press the Enter key. A list of all currently running services marked with corresponding names will be displayed.

If the given command doesn't work, try using the following code ls /etc/rc.d/

Restart Services in Linux Step 3
Restart Services in Linux Step 3

Step 3. Find the file name corresponding to the service you want to restart

Normally the service name (for example "Apache") is displayed on the left side of the screen, while the file name (for example "httpd" or "apache2", depending on the Linux distribution in use) is displayed on the right side.

Restart Services in Linux Step 4
Restart Services in Linux Step 4

Step 4. Enter the command to restart the service you want

Enter the code sudo systemctl restart [service_name] in the "Terminal" window replacing the parameter [service_name] with the name of the file corresponding to the service you want to restart, then press the Enter key.

For example, if you want to restart the Apache server service on Ubuntu Linux, you will need to type the following command sudo systemctl restart apache2 inside the "Terminal" window

Restart Services in Linux Step 5
Restart Services in Linux Step 5

Step 5. Enter your password when prompted

Enter the password you use to log in as a system administrator and press the Enter key. At this point the indicated service will be restarted.

If the service does not restart, try running the command sudo systemctl stop [service_name], press the Enter key and finally execute the command sudo systemctl start [service_name]

Advice

  • You can use the "chkconfig" command to add or remove services that need to run when the system boots.
  • To view a complete list of all services currently present in all directories of the computer, execute the command ps -A in the "Terminal" window.

Recommended: