Within the scope of Linux administration, management of services and processes is important to ensure system stability and performance. systemctl command, which serves as a central utility for managing SystemD services and units. The system service manager manages the boot process and server processes. In this tutorial, we are discussing system services and socket units, which handle system daemons and network services.

Daemons are the services or processes that run in task background or in wait to run. Generally, the daemons start on boot time and it end when the system shutdown or we can manually close the process or down the daemon.

A socket is for communication which is used by a daemon. The socket is responsible for communication between local or remote clients. The socket can send and receive communication and can bind to port, service, and machine and in an address in the header of the packet.

Understanding SystemD and Systemctl units

Before immersing into the complexity of systems, it is important to understand the fundamentals of SystemD. SystemD is a system and services manager for Linux-based operating systems, designed to replace the traditional SysV init system. It offers advanced features such as parallel startup processes, on-demand service activation, and dependency management.

The systemctl command is to manage different types of systemd services and Units. There are different types of units available in the based system, the below command will display will list of available units.

Available SystemD unit types:

service
mount
swap
socket
target
device
automount
timer
path
slice
scope

Above was the output of the available unit on systems. Here we will discuss some basic units, which are very common.

Service Unit:  This unit will call with .service extension and it lists system services. This type of unit works when we need to start a daemon frequently like SSH, web server network services etc.

Path Unit:  Same as other units path units have a .path extension and are used for services that are in spool directories.

Below is the command to list all mount units on the system. You can put any one of them from a list of units list like  service, socket, target, device, mount, automount, snapshot, timer, swap, path, slice, scope

SystemD List all the units

Syntax :#  systemctl list-units --type=[unit_name]
systemctl list-units --type=mountl

OUTPUT :

Show active and inactive sockets :

The below syntax will show all active and inactive sockets on the system.

# systemctl list-units --type=[unit_name]  --all

List all the services on the services unit

Here we are going to check the installed and running status of service on the system.

# systemctl list-units --type=service

Viewing Service Status

With Systemctl, administrators can easily check the status of services to find out whether they are running, stopped, or experiencing problems. The command systemctl status <service_name> provides detailed information about the specified service, including its current state and recent logs

systemctl status chronyd

Starting and Stopping Services

systemctl facilitates seamless starting and stopping of services with simple commands. To start a service, the syntax sudo systemctl start <service_name> is employed, while sudo systemctl stop <service_name> stops the operation of the service.

systemctl start/stop [UNIT NAME]

Enabling and Disabling Services

Enabling a service ensures that it starts automatically on system boot while disabling it stops the automatic startup. The commands below are used to enable and disable services respectively.

 systemctl enable <service_name>
 systemctl disable <service_name> 

Restarting and Reloading Services

In scenarios where changes are made to the service configuration, administrators can reload the configuration without completely restarting the service. The systemctl reload <service_name> command reloads the service configuration, while systemctl restart <service_name> initiates a complete service restart.

Viewing Service Logs

systemctl facilitates easy access to service logs, enabling administrators to diagnose problems and track system events effectively. The command journalctl -u <service_name> displays logs specific to the specified service, aiding troubleshooting and analysis.

The systemctl command serves as a versatile and indispensable tool for managing SystemD services in Linux environments.systemctl can manage both system-level services that affect the entire system and user-level services specific to individual users.

You can read more articles on my blog post by clicking here.

By Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks! Sachin G Follow me on LinkedIn and x formerly twitter