| by Arround The Web | No comments

Service vs. Systemctl

The service and systemctl are two command-line utilities used to manage system services. Both utilities belong to two different init systems, SysV, and systemd respectively.

In this guide, I will be discussing the service and systemctl commands, and how they are different when it comes to service management.

Before going any further, let’s first understand two popular Linux init systems; System and Systemd.

System V vs. Systemd

The init system on Linux is a crucial part of the boot process. It is the first process with PID 1 that initiates when the system boots up. It then starts the processes present in the inittab file. System V also knows a SysV and systemd are popular Linux init systems.

The SysV is an older init system and has been a part of older Unix and Linux distributions. It manages the system services using the scripts located in the /etc/init.d. Some Linux distributions that are still using SysV are Slackware, Gentoo, and antiX Linux.

On the other hand, systemd launched in 2010 and was quickly adopted by many Linux distributions. The systemd init system manages the services through .service files. It is now a part of all modern Linux distributions including, Red Hat Enterprise Linux, CentOS, Amazon Linux, Fedora, Debian, Ubuntu, and distributions based on these operating systems.

The systemd is much more efficient compared to SysV. It provides faster booting time, efficient service management, and dependency handling.

Both init systems provide two command-line utilities for service management.

In the following sections of the guide, I will discuss these two utilities.

service Command

The service command is a script wrapper that runs scripts located in the /etc/init.d directory. It was developed to manage the service of SysV or System V init system. The Linux distributions that use SysV as an init system use the service command for service management.

The general syntax to use the service command is given below.

service [service_name] [action]

To get the status of the services controlled by System V, use the service command with the –status-all option.

service --status-all

The + indicates that the service is running, and the shows that the service is inactive.

The current status of any specific service can also be checked by mentioning the service name.

service [service_name] status

Some other useful service commands such as starting, stopping, and restarting a service are listed below.

service [service_name] start

service [service_name] stop

service [service_name] restart

This service command provides basic control to manage services. Most of the Linux distributions have replaced SysV as an init system, but due to legacy compatibility, this command still comes in many latest Linux distributions out-of-the-box.

systemctl Command

Using the systemctl command, you can control services in the /lib/systemd/system and /etc/systemd/system directories. It is a component of systemd; an init system found in the majority of contemporary Linux distributions.

The systemctl is designed to provide more control over system service management. The general syntax for using the systemctl command is given below:

systemctl [option] [service_name]

To check the status of all services, use the following command.

systemctl list-units --type=service --all

For a specific service use:

systemctl status [service_name]

Commands for basic management of the service using systemctl are given below:

systemctl enable [service_name]

systemctl start [service_name]

systemctl stop [service_name]

systemctl disable [service_name]

systemctl restart [service_name]

The systemctl command goes beyond when it comes to controlling services. The table below contains some advanced systemctl commands.

list-paths To list the path of all services in memory
is-active [service_name] To check if the service or unit is running or not
list-dependencies [service_name] To print the list of dependencies of the specified service
reset-failed To reset the services that are failed to load due to some abnormality
mask [service_name] To disable the service and makes it unable to start
get-default To print the default run level or target
set-default [target] To set the default run level or target
is-system-running To check the operational state of the system
reboot To reboot the system
poweroff To shut down the system

Why there is still a service Command in Linux Distributions with systemd init System

The service command is still part of many Linux distributions because it is a wrapper script and abstracts the underlying init system, whether it is SysV or systemctl. For example, on Ubuntu, the service command redirects to the systemctl.

Conclusion

The service and systemctl are two command line utilities belonging to SysV and systemd init systems, respectively. Despite the replacement of the service command in modern Linux distributions, it remains a key tool for maintaining services due to simplicity, and compatibility. The systemctl, on the other hand, is a part of all current Linux distributions and provides advanced options for service administration.

Share Button

Source: linuxhint.com

Leave a Reply