- 10+ commands to list all systemctl services with status
- Are you new to systemd and systemctl?
- systemctl list unit files loaded in memory
- List active unit files
- List all the unit files
- systemctl list installed unit files
- List type of unit files
- systemctl list services
- systemctl list mount files
- List state of services
- systemctl list enabled services
- systemctl list disabled services
- systemctl list running services
- systemctl list failed services
- Check service status of individual unit file
- Conclusion
- References
- How to List Running Services in Linux
- Detecting the System Manger
- Listing Services in the systemd Service Manager
- Using the systemctl Command
- Listing the ACTIVE Services using the systemctl Command
- Listing the FAILED Services using the systemctl Command
- Listing the running Services using the systemctl Command
- Listing the exited Services using the systemctl Command
- Listing Services in the SysV Service Manager
- Listing the Services with service Command
- Listing Services with the ls Command
- Conclusion
10+ commands to list all systemctl services with status
In this tutorial I will share the commands which you can use to list systemctl services along with their state. You can use these methods in scripts to add service status checks to make sure service is in running or failed state.
Are you new to systemd and systemctl?
With RHEL/CentOS 7, now we have services based on systemd and the SysV scripts are deprecated. If you are new to systemd then I would suggest reading this another article where I have done 1:1 comparison between SysV and systemd services.
Now with systemd the traditional Linux commands such as chckconfig , service etc are not supported any more. Although you can still use these commands but they can be removed in upcoming releases.
For example, with RHEL/CentOS 6 we used to use chkconfig to enable or disable service at different run level. Now with RHEL 8 also I see we are allowed to use chkconfig
# chkconfig postfix on Note: Forwarding request to 'systemctl enable postfix.service'. Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
But the request is internally routed to systemctl . Similarly you can restart a service using traditional command i.e. service . For example, to restart sshd :
# service sshd restart Redirecting to /bin/systemctl restart sshd.service
This request was also transferred to systemctl .
So I hope you understood the point, at the time of writing this article with RHEL 8.1
# cat /etc/redhat-release Red Hat Enterprise Linux release 8.1 (Ootpa)
we are still allowed to use traditional SysV commands but it can be removed in any release now. So I would strongly recommend users to start using systemctl commands as they are very user friendly and powerful tool with the amount of options they support.
With systemd we have unit files which are further classified into service , socket , target etc. So you must be very clear on your requirement if you wish to list only services, or sockets or any other type of unit.
systemctl list unit files loaded in memory
List active unit files
First of all we will list all the unit files which are currently available in the memory of our Linux server. This command will list only the active units from the server’s memory:
List all the unit files
To list all the units independent of their state add » —all » to this command
As you can see now it is loading all the unit files including failed , inactive unit files
systemctl list installed unit files
Now list-units shows the list of units which are currently loaded in the memory but not necessarily installed on the server. To view the list of unit files which are currently installed on our server we use:
Here this command will show all the installed unit files independent of their state unlike list-units which shows only the active unit files. Adding —all with this command will have no advantage.
List type of unit files
There can be different types of unit files such as service, socket, mount etc. To further filter the unit files we can add type= argument with list-unit-files . The argument should be a comma-separated list of unit types.
systemctl list services
To list all the installed systemctl services from our Linux server:
# systemctl list-unit-files --type=service
This should give us a complete list of installed services (independent of it’s state)
systemctl list mount files
With systemd all the partitions and file system are mounted as part of mount type unit files. So we can also list all the mount type unit files available on our server using type=mount
# systemctl list-units --all --type=mount
We can further use this with different other type of unit files such as socket, target etc.
List state of services
To check if a service is enabled/disabled/static/indirect, you must use list-unit-files with systemctl while to check if a service is running/active/failed/dead etc then you must use systemctl list-units . To get complete list of supported options with list-units and —state , use systemctl —state=help
systemctl list enabled services
To list all the service unit files which are currently in enabled state use —state=enabled
# systemctl list-unit-files --type=service --state=enabled
systemctl list disabled services
We can provided multiple state type with —state= argument where individual state values will be comma separated. For example to list all the systemctl service which are either enabled or disabled
# systemctl list-unit-files --type=service --state=enabled,disabled
systemctl list running services
To list the running services we will use list-units in combination with —type=service and —state=running
# systemctl list-units --type=service --state=running
systemctl list failed services
To list failed services you can use —state=failed
# systemctl list-units --type=service --state=failed
OR alternatively we can directly use
Check service status of individual unit file
Now the above commands will give you the status of all the unit files which are installed or available on your server. To check the status of individual file we do not want to use those commands in combination with grep and other filter utility.
Now assuming I wish to check the status of sshd service. So I can use
which can give me a long list of output along with the actual status such as active, running loaded. Now these three states can also be grepped individually using the properties of a unit file
To check if a systemctl service is running or not use:
# systemctl show sshd --property=SubState SubState=running
To check if a service is active or inactive :
# systemctl show sshd --property=ActiveState ActiveState=active
# systemctl is-active sshd active
To check if a service is loaded or not:
# systemctl show sshd --property=LoadState LoadState=loaded
So we can individually grep the state of individual services using their properties. To list all the properties of a service you can use:
Conclusion
In this article we learned little bit more about systemd and systemctl unit files. I have explained about the different types of unit files and commands using which we can get the list of running services, sockets, targets etc with systemctl . We can also get individual status of services using the property of unit files which gives us much more control over the details of each service. We can use these properties in scripts for automation purpose.
Lastly I hope the steps from the article to list running services on Linux was helpful. So, let me know your suggestions and feedback using the comment section.
References
I have used below external references for this tutorial guide
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
How to List Running Services in Linux
In simpler terms, a Linux service is a server’s response to a request that performs a specific task. It is an application or a program that generally executes in the background.
As a user, you are mostly unaware of all the services running in the background because there are plenty of them.
You might have run through the term daemon most probably while working or learning about services. Daemon is a non-interactive program that runs in the background and strictly does not provide any interfaces for the user to control it.
Some of the common characteristics of a Linux service are:
- There is no GUI(Graphical User Interface).
- Most of the native services start along with the start of the OS.
- Some services wait for an interrupt or a signal to get started.
Some common examples of Linux services are mysql, apparmor, httpd and nfs.
Table of Contents
Detecting the System Manger
Detecting the system manager of your Linux system is the elementary step to listing the running services. This step is essential as the commands for listing the services are based on the system manager.
The system manager is the first process that starts in your system. So, you can use the following command to list the first process in the system.
The output looks like this if the system manager is systemd.
PID TTY TIME CMD 1 ? 00:00:02 systemd
systemd is used in the newer Linux distributions.
If the system manager used is SysV , the output looks like this.
PID TTY TIME CMD 1 ? 00:00:02 init
SysV is also known as init or initialization. It was used in early Linux distributions, and lately, it has been replaced by systemd .
Thus, you can find the system manager from the CMD column of the outputs above. According to the service manager present, you can use the respective methods.
Listing Services in the systemd Service Manager
There are a couple of ways to list the running services when the system manager is systemd , and let’s explore each of them.
Using the systemctl Command
You can use the systemctl command to list the services in your Linux system.
Using the list-units subcommand with the —type=service option will list all the services. It includes active, failed, active (exited), and active (running) services.
systemctl list-units --type=service
The output of the above command is shown below.
In the output above, you can notice several columns. Let’s get to know what they represent.
UNIT: It is an object that starts, stops and manages the services.
LOAD: It states whether the particular unit is correctly loaded.
ACTIVE: It is a high-level state that determines whether the unit is active.
SUB: It represents the low-level activation state of the unit.
DESCRIPTION: It describes the task that the unit performs.
In the sections below, you will learn to list the services according to their states. Some of the systemd states are active, inactive, activating, deactivating, failed, not-found, dead, etc.
Listing the ACTIVE Services using the systemctl Command
You can use specific options and the systemctl command to filter the services. With the —state option, you can set the state of the services. For example, if you want only the active services listed, you can use the following command.
systemctl list-units --type=service --state=active
We have used the —state option with the value active to denote only the active services. In the output below, you can see the active status of all the units.
Listing the FAILED Services using the systemctl Command
Similarly, you can list only the failed services with the following command.
systemctl list-units --type=service --state=failed
Listing the running Services using the systemctl Command
To list only the running services, use the following command.
systemctl list-units --type=service --state=running
A running service has an active value for the ACTIVE state and a running value for the SUB state.
Listing the exited Services using the systemctl Command
Exited services are the one-shot type of services which does their job and are closed. The following command can be used to list the exited services.
systemctl list-units --type=service --state=exited
The ACTIVE state holds the value active for exited service, while the SUB state has the value exited.
Listing Services in the SysV Service Manager
In this section, you will learn a few ways of listing the system’s services that use the SysV service manager.
Listing the Services with service Command
In the system with the SysV service manager, you can use the service command to list all the services.
The output of the command is shown below.
The symbols in the brackets represent the status of the services.
- –: It represents the services that are stopped.
- +: It represents the services that are running.
- ?: It represents the services without the status command.
To list only the running services, you can use the following command.
service --status-all | grep running
Listing Services with the ls Command
Another way you can list the services of init scripts is using the ls command. Using the ls command on the directory containing the init scripts does the job. The init scripts are located in the path /etc/init.d. An example is shown below.
The output of the above command is shown below.
Conclusion
In this tutorial, you learned to identify the system manager used in your Linux system. Thus, you grasped the idea of using the various commands to list the Linux services.