Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

Listing Linux Services with Systemctl - DesignLinux

designlinux 0 Comments

In Linux, a service is a program that runs in the background . Services can be started on-demand or at the boot time.

If you are using Linux as your primary operating system or development, platform you will deal with different services such as webserver, ssh or, cron . Knowing how to list running services or check the service status is important when debugging system issues.

Most of the recent Linux distributions are using systemd as the default init system and service manager.

Systemd is a suite of tools for managing Linux systems. It is used to boot up the machine, manage services, automount filesystems, log events, setup hostname, and other system tasks.

This article explains how to list services in Linux.

Listing Linux Services #

Systemd uses the concept of units, which can be services, sockets, mount points, devices, etc. Units are defined using text files in ini format. These files include information about the unit, its settings, and commands to execute. The filename extensions define the unit file type. For example, system service unit files have a .service extension.

systemctl is a command-line utility that is used for controlling systemd and managing services. It is part of the systemd ecosystem and is available by default on all systems.

To get a list of all loaded service units, type:

sudo systemctl list-units --type service
UNIT          LOAD      ACTIVE SUB     DESCRIPTION                                                              
cron.service  loaded    active running Regular background program processing daemon 
...

Each line of output contains the following columns from left to right:

  • UNIT – The name of the service unit.
  • LOAD – Information about whether the unit file has been loaded in the memory.
  • ACTIVE – The high-level unit file activation state, which can be active, reloading, inactive, failed, activating, deactivating. It is a generalization of the SUB column.
  • SUB – The low-level unit file activation state. The value of this field depends on the unit type. For example, a unit of type service can be in one of the following states, dead, exited, failed, inactive, or running.
  • DESCRIPTION – Short description of the unit file.

By default, the command lists only the loaded active units. To see loaded but inactive units too, pass the --all option:

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

If you want to see all installed unit files, not only the loaded, use:

sudo systemctl list-unit-files

Displaying Service Status #

To check the status of a service, use the systemctl status command:

sudo systemctl status <service_name>.service

Where <service_name> is the name of the service unit you want to check. For example to determine the current status of the nginx service you would run:

sudo systemctl status nginx.service
You can ommit the suffix “.service”. systemctl status nginx is same as 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 2020-12-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 linuxize.dev systemd[1]: Starting A high performance web server and a reverse proxy server...

The command will print the following information:

  • Loaded – Whether the service unit has been loaded and the full path to the unit file. It also shows whether the unit is enabled to start on boot time.
  • Active – Whether the service is active and running. If your terminal supports colors and the service is active and running, the dot (●) and “active (running)” part will be printed in green. The line also shows how long the service is running.
  • Docs – The service documentation.
  • Process – Information about the service processes.
  • Main PID – The service PID.
  • Tasks – The number of tasks accounted for the unit and the tasks limit.
  • Memory – Information about used memory.
  • CGroup – Information about related Control Groups.

If you only want to check the service status, use the systemctl is-active command. For example, to verify that the nginx service is running, you would run:

systemctl is-active nginx.service
active

The command will show you the service status. If the service is active, the command returns an exit status of 0, which can be useful when using the command inside shell scripts.

Conclusion #

We have shown you how to use the systemctl command to list Linux services and check their status.

If you have any questions or feedback, feel free to comment below.

terminal

Related

Tags: terminal

How to Install Notepad++ on Debian 10

Prev Post

How to Install Python 3.9 on Debian 10

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 645
  • 1,055,417

DesignLinux.com © All rights reserved

Go to mobile version