How to List Systemd Services in Linux
Check what systemd services run on your Linux system in this tutorial.
While systemd solves many problems with system management, it is also confusing sometimes.
Even a simple task like listing systemd services could send you thinking.
In this article, I'll show you how to list systemd services. I'll also explain the output so that it is easier for you to understand the different states of the services.
I presume that you have some knowledge of systemd but even if you don't, it should be fine.
How to list active services in systemd
systemd services are managed by the
systemctl command. If you run
systemctl without any arguments, it invokes the default
list-units sub-command and it lists various types of systemd units like services, sockets, targets etc.
But your aim is to list the services so you specify the unit type with
--type flag like this:
Did you notice that I didn't specify the
list-units sub-command because it is the default? If you want to follow the convention, you may specify that as well. I prefer it this way and I'll follow this convention in the rest of the tutorial.
systemctl list-units --type=service
In both cases the output will be the same. By default, this command shows only loaded and active services in alphabetical order:
UNIT LOAD ACTIVE SUB DESCRIPTION accounts-daemon.service loaded active running Accounts Service acpid.service loaded active running ACPI event daemon alsa-restore.service loaded active exited Save/Restore Sound Card State apparmor.service loaded active exited Load AppArmor profiles apport.service loaded active exited LSB: automatic crash report generation
Let me explain the output:
UNIT: name of the systemd unit.
LOAD: whether the unit configuration file has been parsed by systemd.
ACTIVE: high level state of the unit.
SUB: low level state of the unit. An active unit can be in the running state or exited state. This value depends on the service type.
As you can see, you could list the loaded services on your Linux system. But an active systemd service could be running or could be exited (after running successfully).
List all the running systemd services
The active state can also have a sub-status like running, exited etc. You can use the same
--state flag with the sub-state.
To list the running systemd services, use the
--state=running flag like this:
systemctl list-units --type=service --state=running
Here's a sample output for my system showing some of the running systemd services:
UNIT LOAD ACTIVE SUB DESCRIPTION accounts-daemon.service loaded active running Accounts Service acpid.service loaded active running ACPI event daemon avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack bluetooth.service loaded active running Bluetooth service bolt.service loaded active running Thunderbolt system service
List all loaded systemd services including the inactive ones
By default, the systemctl command only displays the loaded and active units.
If you want to list all the loaded services including the inactive ones, use the
systemctl list-units --all --type=service
You can now see even the inactive services:
UNIT LOAD ACTIVE SUB DESCRIPTION accounts-daemon.service loaded active running Accounts Service acpid.service loaded active running ACPI event daemon alsa-restore.service loaded active exited Save/Restore Sound Card State alsa-state.service loaded inactive dead Manage Sound Card State (restore and store) anacron.service loaded inactive dead Run anacron jobs apparmor.service loaded active exited Load AppArmor profiles
List all the inactive systemd services
If you want to see only the inactive services, you can combine various flags like
--state like this:
systemctl list-units --all --type=service --state=inactive
As you can see in the output, it displays all the inactive systemd services:
UNIT LOAD ACTIVE SUB DESCRIPTION alsa-state.service loaded inactive dead Manage Sound Card State (restore and store) anacron.service loaded inactive dead Run anacron jobs apport-autoreport.service loaded inactive dead Process error reports when automatic reporting is enabled apt-daily-upgrade.service loaded inactive dead Daily apt upgrade and clean activities apt-daily.service loaded inactive dead Daily apt download activities ● auditd.service not-found inactive dead auditd.service
List all the installed systemd services (even if they are not loaded)
Every systemd unit, be it service or socket or any other unit, has a unit file which
systemctl list-unit-files --type=service
Here's what you should see:
UNIT FILE STATE VENDOR PRESET accounts-daemon.service enabled enabled acpid.service disabled enabled alsa-restore.service static enabled alsa-state.service static enabled alsa-utils.service masked enabled anacron.service enabled enabled apparmor.service enabled enabled apport-autoreport.service static enabled apport-[email protected] static enabled
Explaining each state type will be too lengthy and is not in the scope of this article. Maybe I'll write about it in the future.
List all systemd services that will be run at each boot automatically
To see all the systemd services that will run automatically every time your system boots, use this command:
systemctl list-unit-files --type=service --state=enabled
Are you confused with the enabled state? That's normal. Many new user confuse an enabled system service with a running service.
However, an enabled systemd service means that the service will be activated automatically when the system boots.
UNIT FILE STATE VENDOR PRESET accounts-daemon.service enabled enabled anacron.service enabled enabled apparmor.service enabled enabled [email protected] enabled enabled avahi-daemon.service enabled enabled binfmt-support.service enabled enabled bluetooth.service enabled enabled console-setup.service enabled enabled containerd.service enabled enabled cron.service enabled enabled cups-browsed.service enabled enabled cups.service enabled enabled dbus-fi.w1.wpa_supplicant1.service enabled enabled
Do you notice the Vendor Preset? It was also present in the previous example.
Vendor preset defines the automatic behavior of the systemd unit when a program is installed.
Suppose you installed a new program XYZ. This XYZ has a systemd service called xyz.service with vendor preset enabled. This means that after installing the program, when you boot the system, this xyz.service will be activated automatically at the boot time.
If the vendor preset is disabled, you'll have to manually set it to enable. Once it is enabled, it starts automatically each boot.
sudo systemd enable xyz.service
Display the status of a particular systemd service
So far, you have seen various ways of listing services. But nothing focuses on a single service.
You can get detailed information on a systemd service using the
status sub-command of systemctl. Tab completion works with this command.
systemctl status <service_name>
Here's an example with the network manager service:
abhishek@itsfoss:~$ systemctl status NetworkManager.service ● NetworkManager.service - Network Manager Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-07-23 08:12:44 IST; 3h 8min ago Docs: man:NetworkManager(8) Main PID: 711 (NetworkManager) Tasks: 3 (limit: 9157) Memory: 13.6M CGroup: /system.slice/NetworkManager.service └─711 /usr/sbin/NetworkManager --no-daemon Jul 23 08:12:50 itsfoss NetworkManager: <info> [1595472170.7159] device (wlp58s0): Activation: successful, device activated. Jul 23 08:12:50 itsfoss NetworkManager: <info> [1595472170.7179] manager: startup complete Jul 23 08:12:51 itsfoss NetworkManager: <info> [1595472171.5592] manager: NetworkManager state is now CONNECTED_GLOBAL Jul 23 08:12:52 itsfoss NetworkManager: <info> [1595472172.7973] dhcp6 (wlp58s0): activation: beginning transaction (timeout in 45 seconds) Jul 23 08:12:52 itsfoss NetworkManager: <info> [1595472172.8017] policy: set 'JioFi3_215810' (wlp58s0) as default for IPv6 routing and DNS Jul 23 08:12:52 itsfoss NetworkManager: <info> [1595472172.8058] dhcp6 (wlp58s0): option dhcp6_name_servers => 'fe80::a8dc:79ff:fe1b:57fe' Jul 23 08:12:52 itsfoss NetworkManager: <info> [1595472172.8059] dhcp6 (wlp58s0): state changed unknown -> bound Jul 23 08:12:59 itsfoss NetworkManager: <info> [1595472179.9251] agent-manager: agent[bdd71d4a66098713,:1.84/org.gnome.Shell.NetworkAgent/1> Jul 23 11:18:10 itsfoss NetworkManager: <info> [1595483290.7874] manager: NetworkManager state is now CONNECTED_SITE Jul 23 11:18:11 itsfoss NetworkManager: <info> [1595483291.5893] manager: NetworkManager state is now CONNECTED_GLOBAL
You can see that it provides plenty of useful information like the state of the service, man page of the service, memory it consumes, process id etc. It also shows the last few journald logs for the service.
If you want to check whether a service is active or not in a shell script, you can use the
is-active sub-command. The output is 0 for active.
systemctl is-active application.service
Similarly, if you want to check whether a service is enabled (set to start automatically at boot time), you can use
is-enabled sub-command. Output is 0 for enabled service.
systemctl is-enabled application.service
I think you now have a better understanding on listing systemd services. I do hope you learned a few new things about systemd and systemctl command.
Don't hesitate to provide your feedback, questions or suggestions in the comment section.