Listing the services gives you an idea of the activity status of multiple services.
But why would one be interested in checking the activity status of a service? Well, it is one of the first few steps system administrators take for troubleshooting purposes in Linux.
As most Linux systems come with systemd these days, you can use the command below to list the services:
systemctl list-units --type=service
But there are other init systems such as runit and SysVinit that are used to manage Linux services. The above command won't work for them.
Fret not! In this tutorial, I will show you how to check services in:
- systemd
- sysvinit
- runit
- OpenRC
So let's start with the most popular systemd to list services on Linux.
Use the systemctl command to list services
If you are using Ubuntu, Debian, Arch, Fedora, or any other mainline distro, your system is powered by systemd, an init system responsible to start and manage services.
And to manage Linux services with systemd, you use the systemctl command.
The same goes for listing services:
systemctl list-units --type=service
Here, I have used the list-units
paired with the --type=service
to list all the services.
Did you notice anything strange? It only showed active processes that are either running or exited. Basically, it shows only the active services. if that's what you want, you can relax at this point.
But what if you want to list all the system services, including inactive units? Simple. You use one more flag --all
as shown here:
systemctl list-units --type=service --all
You can now see the inactive services too with inactive
status under the ACTIVE
column.
List running services only
If you want to list only the running services, use:
systemctl list-units --type=service --state=running
Here's the brief of systemctl commands for listing unit files:
Command | Description |
---|---|
systemctl list-units --type=service | List active (running and exited) services |
systemctl list-units --type=service --all | List all services (active and inactive) |
systemctl list-units --type=service --state=running | List only running services |
Use service command to get service list in Linux with sysvinit
In SysVinit systems, such as MX Linux default installation, you can list services using the service
command.
First, open the terminal and run:
service --status-all
This will list sysvinit services, all of them, running, stopped etc.
The above command runs all init scripts in /etc/init.d/
, in alphabetical order, with the status command.
Here, the services are listed with some preceding symbols. As you can see, I have highlighted three of those using yellow color in the above screenshot.
The meaning of those are:
- [ + ] : It is a running Service
- [ - ] : It is a stopped Service
- [ ? ] : Services without a status command
If you just want to list all the available services, use:
ls /etc/init.d
Because, all the init scripts are stored in this directory. But the issue with this is, you cannot say that a script actually belongs to a running service or not.
Listing services in Runit
Here, I have used AntiX Linux Runit version as an example.
In Runit, there is a directory called /etc/sv
where all the available services that can be enabled are listed.
Now, if you want to list the services running currently, you need to list another directory, called /etc/runit/runsvdir/current
ls /etc/runit/runsvdir/current/
On a running system, this currently running services are accessible via the /var/service symlink.
ls /etc/service
Or in some systems,
ls /var/service
You can show the show status of enabled services by:
sv status /etc/service/*
Or in some systems,
sv status /var/service
Listing services in OpenRC
In OpenRC, we use the command rc-status
to list the services.
Open a terminal and run:
rc-status
This will show the scripts that exist in runlevels.
To show services from all runlevels, run:
rc-status -a
To show the service list, run:
rc-status --servicelist
A similar function is performed, if you list the /etc/initrd
, but this time, listing the services, without status.
ls /etc/init.d
You can use the below command to get various other options available:
rc-status --help
Conclusion
So, now you know how to list running services in a Linux machine. Since there are multiple init systems in the fragmented Linux ecosystem, I have covered the popular ones not just systemd service manager.
Hope it helps you.