Open In App

How to Start, Stop and Restart Services in Linux Using systemctl Command

Improve
Improve
Like Article
Like
Save
Share
Report

System services play a crucial role in the functioning of a Linux system, handling various tasks and processes in the background. systemctl is a powerful command-line tool that allows users to manage these services effectively. In this article, we will explore the basics of using systemctl to start, stop, restart, enable, disable and display status of services in a Linux environment.

What is systemctl

Before diving into service management, it’s essential to understand the basics of systemctl. This command is used to control the systemd system and service manager, which is a central component in modern Linux distributions.

systemctl [command] [unit]

Here,

  • command: Action to be performed (e.g., start, stop, restart, enable, disable).
  • unit: The service or unit to be affected.

Systemctl is a controller or utility of Systemd(is an init system with compost for a set of programs executed in the background), with auxiliary in manage services, these commands are executed in mode root if you aren’t mode root the system, requesting the password of root.

1. How to List Available systemd units in Linux

To list available systems units or to List all Services in Linux we use the following command:

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

2. How to Start a System Service in Linux

Syntax:

sudo systemctl start service.service

The command start serves for starting (activate) one or more units specified on the command line.

Example:

sudo systemctl start mariadb
systemctl start

Command Start

3. How to Stop a System Service in Linux

Syntax:

sudo systemctl stop service.service

The command stop serves for stopping the service or (deactivate) one or more units specified on the command line.

Example:

sudo systemctl stop mariadb
systemctl stop

Command Stop and Status

4. How to Display Status of a System Service in linux

Syntax:

sudo systemctl status service.service

The command status serves to check the status of the service. Show terse runtime status information about one or more units, followed by the most recent log data from the journal. If no units are specified, show system status.

Example:

sudo systemctl status mariadb
systemctl status

Command Status

5. How to restart a System Service in Linux

Syntax:

sudo systemctl restart service.service

The command restart serves for restarting the service in execution. Stop and then start one or more units specified on the command line. If the units are not running yet, they will be started.

Example:

sudo systemctl restart mariadb
systemctl restart

Command Restart

6. How to Enable a System Service in Linux

Syntax:

sudo systemctl enable name_service.service

The enable command serves for executing the service since the initialization if consists of one or more units or unit instances. This will create a set of symlinks, as encoded in the [Install] sections of the indicated unit files. the system manager configuration is reloaded (in a way equivalent to daemon-reload), in order to ensure the changes are taken into account immediately. 

Example

sudo systemctl enable mariadb

systemctl enable

Command Enable

Command Status

7. How to Disable a System Service in Linux

Syntax:

sudo systemctl disable name_service.service

The disable command serves for withdrawing the service since the initialization of one or more units. This removes all symlinks to the unit files backing the specified units from the unit configuration directory and hence undoes any changes made by enabling or link.

Example:

sudo systemctl disable mariadb

systemctl disable

Command Disable

Command Status

Frequently Asked Questions on systemctl – FAQs

How do I list all system services?

Use `systemctl list-unit-files --type service` to view a list of all available service files. You can add `-a` for additional details like status and enabled state.

How do I check the status of a specific service?

Use `systemctl status <service_name>` to see if the service is running, active (recently stopped), or inactive (never started). This reveals important information like memory usage and active connections.

How do I start, stop, restart a service?

For starting, use :

sudo systemctl start <service_name>

For stopping, use :

sudo systemctl stop <service_name>

To restart, use :

sudo systemctl restart <service_name>

Note : Remember to replace <service_name> with the actual service name.

How do I make a service start automatically at boot?

Use sudo `systemctl enable <service_name>` to set the service to start automatically when the system boots.

To disable automatic startup, use `sudo systemctl disable <service_name>`.

Conclusion

In this article we discussed systemctl which is a vital command-line tool for managing system services in Linux, playing a crucial role in tasks such as starting, stopping, restarting, enabling, and disabling services. This article provided a comprehensive guide to systemctl, covering its syntax and key commands. From listing available systemd units to enabling or disabling automatic startup, each command contributes to effective service management. The article also addressed common questions, offering practical solutions for tasks such as checking service status, starting, stopping, and restarting services, and enabling or disabling automatic startup. Overall, understanding and mastering systemctl commands are essential for Linux administrators to ensure the stability and optimal performance of their systems.



Last Updated : 11 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads