How to Start, Stop, and Restart Services in Linux

March 27, 2024

Introduction

Using the systemctl command, Linux provides fine-grained control over system services through systemd. Services can be turned on, off, restarted, reloaded, as well as enabled or disabled at boot.

This guide will show you how to start, stop, and restart services in Linux.

How to Start, Stop, and Restart Services in Linux

Prerequisites

  • Access to a user account with sudo or root privileges.
  • Access to the terminal.
  • A Linux system (this tutorial uses Ubuntu 22.04).

What Is systemctl?

systemctl is an essential command-line tool for system administrators and users on Linux systems utilizing systemd, the default init system for many Linux distributions.

systemctl provides an efficient way to manage Linux services. Services in Linux are background processes crucial for the proper functioning of the operating system and different applications.

The systemctl syntax is: 

systemctl [options] [command] [unit] 

The syntax consists of:

  • systemctl. The command that interacts with systemd and manages services.
  • [options]. Optional arguments that modify the systemctl command behavior. 
  • [command]. The action to be performed on the specified units. 
  • [unit]. Units to be acted upon, like services, sockets, targets, etc. If no units are specified, the command applies to all units of the specified type.

systemctl vs. service

systemctl and service are command-line tools used to manage services in Linux. However, they are associated with different init systems. Init is the initialization process, the first process that starts when the computer boots up. It is responsible for initializing the system and starting other processes and services.

While systemctl is used to manage Linux services that use systemd as their init system, service is a legacy command-line tool used to manage services in Linux distributions that use traditional init systems like SysVinit or Upstart.

systemctl provides more advanced features than the traditional service command. However, both commands are available on modern Linux distributions for compatibility reasons.

How to Start a Service

To start a service in Linux, type in the following:

sudo systemctl start [service-name]

For instance, the command to start the Apache service is:

sudo systemctl start apache2

The command has no output. Verify the service is active with:

sudo systemctl status apache2
sudo systemctl status apache2 terminal output- service is active

The output shows the service is active (running).

To configure a service to start when the system boots, use the command:

sudo systemctl enable [service-name]

For example, enable Apache to start with the system boot with:

sudo systemctl enable apache2
sudo systemctl enable apache2 terminal output

Note: Different Linux distributions sometimes have different names for one service.

How to Stop a Service

To stop an active service in Linux, use the following command:

sudo systemctl stop [service-name]

For example, to stop Apache, execute:

sudo systemctl stop apache2

The command has no output. Check whether the service stopped running:

sudo systemctl status apache2
sudo systemctl status apache2 terminal output service inactive

The output shows the service is inactive (dead).

Another way to ensure the service is not active is to prevent it from starting on boot. Use the command:

sudo systemctl disable [service-name]

For example:

sudo systemctl disable apache2
sudo systemctl disable apache2 terminal output

How to Restart a Service

To restart the service in Linux, use the command:

sudo systemctl restart [service-name]

To restart Apache, use:

sudo systemctl restart apache2

The command has no output. Verify the status with:

sudo systemctl status apache2
terminal output for sudo  systemctl status apache2

How to Reload a Service

Restarting a service involves stopping it completely and then starting it again. On the other hand, reloading a service reloads its configuration files and applies any changes without stopping the service.

To reload a service, run:

sudo systemctl reload [service-name]

For instance, reload Apache with:

sudo systemctl reload apache2

The command has no output. Verify the service is running with:

sudo systemctl status apache2
sudo systemctl status apache2 terminal output

The output shows the service is active and running.

Conclusion

After reading this article, you have learned about systemctl. You also know how to start, stop, restart, and reload a service in Linux.

Next, learn about important Linux commands.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Linux SCP Command: Securely Copy & Transfer Files
March 27, 2024

Tutorial on securely transferring files between Unix or Linux systems using the SCP command. The SCP or...
Read more
How To Use grep Command In Linux/UNIX
February 29, 2024

This guide details the most useful grep commands for Linux / Unix systems. After going through all the...
Read more
How to Use mkdir Command to Make or Create a Linux Directory
December 1, 2023

The mkdir command in Linux allows users to create or make new directories. mkdir stands for "make directory"...
Read more
How to Use IP Command in Linux with Examples
November 22, 2019

The ip command is a Linux net-tool for system and network administrators used for configuring network...
Read more