1. Overview

In the world of Linux, system administration often involves managing various services that keep the operating system and applications running smoothly. The services can range from essential system processes to user-installed applications.

To manage these services, Linux distributions employ service managers, also known as init systems, which are responsible for starting, stopping, and supervising the processes. Popular init systems include systemd, SysV init, and Upstart, among others.

In this tutorial, we’ll explore the process of identifying the service manager on a Linux system using command-line techniques.

2. Understanding Service Managers

Service managers are responsible for initializing and managing system processes or services. They ensure that essential services start at boot time and remain operational throughout the system’s uptime.

Before learning how to identify the service managers, let’s review some of the most prominent choices.

2.1. systemd

systemd is a modern init system and service manager that has gained widespread adoption in many Linux distributions, including CentOS, Fedora, Debian, and Ubuntu.

It’s designed to provide parallelization, on-demand service activation, and a variety of other features.

2.2. SysV Init

The SysV init system was one of the earliest init systems used in Unix-like operating systems. It uses a sequential approach to start and stop services during the boot process.

Some older Linux distributions and Unix systems still use SysV init, but it has been largely replaced by systemd.

2.3. Upstart

Upstart was developed by Ubuntu as an alternative to SysV init.

It aimed to improve boot speed and provide better handling of events and services. However, it’s been largely phased out in favor of systemd in most modern distributions.

3. Why Identify the Service Manager

Different Linux distributions historically used different init systems. For instance, Ubuntu versions prior to 15.04 used Upstart, while CentOS 6 and older versions used SysV init. However, in recent years, systemd have become the dominant init system in many major distributions due to its comprehensive features and improved performance.

Identifying the service manager in Linux helps us understand how services are controlled and managed.

Let’s understand why the service manager in use is essential for various administrative tasks:

3.1. Service Management

Different service managers have their own commands and configurations for managing services. Knowing the right commands streamlines service control.

3.2. Troubleshooting

Service managers affect how services start, stop, and behave. Knowing the service manager can help us troubleshoot the issues.

3.3. Init Script Compatibility

Some systems may still use older init scripts. Recognizing the service manager can help us adapt scripts accordingly.

3.4. Startup Configuration

Different service managers have distinct methods for setting up service startup behavior. This knowledge is crucial for system customization.

4. Determining the Service Manager

In general, we can analyze the command output of the process associated with the init system to determine the service manager. Common results include:

  • If the output is systemd, our system uses the systemd service manager.
  • If the output is init, our system uses the traditional SysV init.
  • If the output is upstart, our system uses the Upstart init system.

We’ll be using a Debian-based Linux distribution for checking which service manager is currently being used.

4.1. Using ps

The ps command is a powerful utility used to display information about running processes. It provides details such as process IDs (PIDs), CPU and memory usage, user ownership, and execution status. It’s a versatile tool for monitoring and managing processes from the command line.

To figure out the service manager that’s in use, let’s use the ps command to check the first process with the PID of 1, as it’s always the init process. Here, -o comm= specifies the output format that displays only the command name:

$ ps -p 1 -o comm=
systemd

The command displays the name of the process associated with PID 1. In this case, it shows the name systemd which is the service manager in use.

4.2. Using pstree

Another way to determine the init system is by inspecting the process tree. The process tree represents all active processes hierarchically.

Let’s check which service manager a Linux machine is using with pstree:

$ pstree -p 1
systemd(1)─┬─ModemManager(639)─┬─{ModemManager}(661)
│ ├─{ModemManager}(668)
│ └─{ModemManager}(675)
├─NetworkManager(610)─┬─{NetworkManager}(663)
...

The output shows the process tree starting from the init process (PID 1), which reveals the name of the init system (systemd in this case).

4.3. Finding the Service Manager by Viewing the /proc/1/comm File

Similarly, viewing the /proc/1/comm file gives us the name of the init process, which corresponds to the name of the service manager being used, such as systemd, init, or any other relevant name.

Let’s check the service manager by viewing the comm file under the /proc directory using the cat command:

$ cat /proc/1/comm 
systemd

The command output displays the name of the init system.

4.4. Finding the Service Manager by Checking Specific Binaries

Init systems have specific binaries associated with them. We can check the binaries to determine the active init system which represents the service manager that’s currently in use:

  • For systemd*,* if we run the systemctl –version command and provide version information, our system uses the systemd service manager.
  • For SysV init, if we run the /sbin/init –version command and provide version information, our system uses the SysV init service manager.
  • For Upstart, if we run the initctl –version command and provide version information, our system uses the Upstart service manager.

5. Conclusion

In this article, we explored various command line methods for determining the service manager in use in Linux machines.

Through straightforward command-line techniques, such as analyzing process output, inspecting process tree hierarchies, and checking for specific binaries, we can readily determine the service manager, whether it’s systemd, Upstart, SysV init, or some other in use.

Recognizing the active service manager facilitates streamlined service control, efficient issue resolution, compatibility with older init scripts, and customization of startup behavior.