Home // Systemctl Service Listing in Linux

Systemctl Service Listing in Linux

0 7 minutes read
| Published on: August 2, 2022 | Last updated on: July 31, 2023

A software that operates in the background on Linux is referred to as a service. It is possible to launch services either manually or automatically when the system boots up.

If you use Linux as your primary operating system or development platform, you will need to interact with a range of services such as webserver, ssh, and cron, among others. When troubleshooting system faults, having the ability to validate the status of services and identify the services that are now operational is critical.

The majority of modern Linux distributions use systemd as their primary init system and service manager. This is especially true of more recent Linux versions.

Systemd is a set of tools for managing Linux systems. It is responsible for booting the computer, managing services, automounting filesystems, logging events, configuring the hostname, and a range of other system tasks.

This tutorial will lead you through listing services in Linux.

Listing Linux Services

Systemd employs the unit notion, which may refer to services, sockets, mount points, devices, and so on. Text files in ini format are used to specify units. These files include information on the device, its settings, and commands to run. The unit file type is defined by the filename extensions. System service unit files, for example, have a.service extension.

systemctl is a command-line tool for managing services and controlling systemd. It belongs to the systemd ecosystem and is installed by default on all platforms.

To retrieve a list of all loaded service units, type

 sudo systemctl list-units --type service

From left to right, each line of output has the following columns:

  • UNIT – The service unit’s name.
  • LOAD – Find out if the unit file has been loaded into memory or not.
  • ACTIVE – The high-level state of the unit file’s activation, and can be active, reloading, inactive, failed, activating, or deactivating. It is a broad statement about the SUB column.
  • SUB – The activation status of a low-level unit file. Depending on the unit type, the value of this field varies. For instance, a unit of type service can be in one of the following states: dead, exited, failed, inactive, or operating.
  • DESCRIPTION – Brief summary of the unit file.

By default, just the loaded active units are shown. To view both loaded and inactive units, use the —all option.

sudo systemctl list-units --type service --all

If you wish to view all installed unit files, not just those currently loaded, use:

sudo systemctl list-unit-files

Viewing Service Status

Use the systemctl status command to determine the current status of a service:

sudo systemctl status <service_name>.service

Where service name is the desired service unit’s name. To discover, for instance, the current status of the nginx service, you might execute:

sudo systemctl status nginx.service

You may omit the “.service” suffix. systemctl status nginx is identical to systemctl

status nginx.service.

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-1-23 19:13:50 UTC; 5s ago
       Docs: man:nginx(8)
    Process: 3061052 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 3061063 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 3061064 (nginx)
      Tasks: 2 (limit: 470)
     Memory: 6.0M
     CGroup: /system.slice/nginx.service
             ├─3061064 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─3061065 nginx: worker process

Dec 23 19:13:50 pcplanet.dev systemd[1]: Starting A high performance web server and a reverse proxy server...

The command will provide the following output:

  • Loaded – Whether or not the service unit has been loaded, as well as the whole path to the unit file. In addition, it indicates if the device is configured to start automatically upon boot.
  • Active – If the service is functioning and operational. If your terminal supports color and the service is active and running, the dot and “active (running)” will be written in green if your terminal supports color and the service is active and running. The line also displays the service’s duration of operation.
  • Docs – Documentation on the service.
  • Process – Details on the service processes.
  • Main PID – The service PID.
  • Tasks – The number of tasks assigned to the unit and the maximum number of tasks.
  • Memory – Information about used memory.
  • CGroup – Information about related Control Groups.

To check the status of a service, use the systemctl is-active command. To test that the nginx service is operating, for instance, you might run:

systemctl is-active nginx.service
active
 

The command will display the status of the service. If the service is running, the command returns an exit status of 0, which is beneficial for employing the command within shell scripts.

Conclusion

We have demonstrated how to use the systemctl command to list and verify the status of Linux services.

If you have any questions or comments, please leave them below.

IF YOU ARE HAVING PROBLEMS WITH THIS GUIDE, EMAIL US AT:

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

Copyright @2022-2024 All Right Reserved – PCPlanet

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. You understand and give your consent that your IP address and browser information might be processed by the security plugins installed on this site. By clicking “Accept”, you consent to the use of ALL the cookies.
.
Accept Read More

Privacy & Cookies Policy