How to Manage systemd Services Using the systemctl Command in Linux | #linux | #linuxsecurity

Managing services is one of the key responsibilities of Linux system administrators. Knowing how to manage system services is also important for Linux users as they might have to deal with services in one way or the other.

This guide takes a look at how to manage systemd services using the systemctl command.

What Is systemd?

Systemd is a system and services manager for Linux operating systems. It is the default service manager in many Linux distros including Ubuntu, Red RHEL, OpenSuse, and Arch Linux. Systemd is a successor to older service managers such as System V and Upstart.

Unlike the System V service manager, systemd aims to be more efficient by starting services in parallel to speed up the Linux boot process. Another unique feature of systemd is that it provides services on-demand i.e. it can defer the start of a service to only when the system needs it, which greatly improves the performance.

Systemd is not only restricted to managing operating processes or services, but can also be used for mounting filesystems, monitor networks, running timers, and more.

Managing systemd Services Using systemctl

In Linux, the systemctl command is responsible for managing systemd services. If you have the  /usr/lib/systemd directory on your system, then you are most likely using the systemd service manager.

You can also run any of the following commands to check if the systemd service manager is available on your system.

systemctl --version
systemd --version

Checking the Status of a Service

To check the status of a particular service on your system, use the status command followed by the name of the service you want to check.

For example, to check the status of the docker service you can run the following command. Docker is a modern virtualization program used by software developers to build applications efficiently.

systemctl status docker

Note: The systemctl help manual refers to the verb after systemctl as a command too, therefore, this guide will stick to that definition for consistency.

output of a linux service status

Related: Reasons to Use Docker Virtualization Software

In addition to listing the status of the service, the status command also gives you important information such as the Process ID of the service, memory usage, and a simple listing of recent changes in the service.

Knowing the status of a service is one of the primary ways you will use to troubleshoot errors or diagnose problems. Before going into details as to why something is not working, system administrators tend to check if the service is up and running first.

Listing Services With systemctl

Often, you will need to know which services are available on your system before you can proceed to manage them. You can use the following command to list all available services on your system.

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

In addition to listing the services available on your system, the command will also show the state of these services. The most common states include; enabled, disabled, masked, etc.

Starting and Stopping Services

The stop command is used for stopping a service that you no longer want running. For example, to stop the docker service:

systemctl stop docker

There are several reasons to stop services on your Linux machine. Unused services consume unnecessary system resources and negatively affect the performance of your PC.

If a service is consuming too much memory, consider other options to manage memory in Linux. Having multiple services running is also a potential security risk because you expose more ports for exploitation to the outside world.

To start a service that is not running, use the start command. For example, to start the docker service that you recently stopped:

systemctl start docker

If you want to stop a service and then start it again immediately, you can use the restart command as follows.

systemctl restart docker

Enabling and Disabling Services

The terms Enabling and Starting services are often confusing to some Linux users. By enabling a service, you are saying that the service should be made available when the system boots, or sets a service ready when specific hardware is plugged in. To enable the docker service on Linux:

systemctl enable docker

To disable a service from starting at boot, you can use the disable command. For example, issue the following command to disable the docker service.

systemctl disable docker

There are many other commands and options that you can use for managing services on your system. Run the help command systemctl –help or take a look at the systemctl man pages if you can’t figure out your way around the command.

man systemctl

Many a time, some services start when the system boots. These services, if not needed by the system, affect the overall performance of the computer. You can easily stop such startup services and daemons on Linux.

How to Control Linux Start-Up Services and Daemons

Linux runs many applications “in the background” that you might not even be aware of. Here’s how to take control of them.

Read Next

About The Author


Original Source link

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *

27 + = 35