Viewing enabled and running services on Linux with systemctl

Systemd and the systemctl command play vital roles in most of today's Linux systems. This post explains commands for peering into some aspects of how they piece of work.

radar grid overlays the pupil of an eye / intrusion detection / scanning / threat assessment
ddukang / Getty Images

A vast majority of Linux systems these days are usingsystemd – a suite of programs aimed at managing and interconnecting different parts of the system.Systemd started replacing the init process back in 2014 and is now the first process that starts when nigh Linux systems boot. To get a quick peek, you tin can run a command like this, which verifies that procedure one is indeed systemd. On this system, ii additional systemd processes are currently also running.

$ ps -C systemd     PID TTY          Time CMD       1 ?        00:00:59 systemd                <===                1244 ?        00:00:00 systemd   54429 ?        00:00:00 systemd              

To see a little more detail, endeavour the command below. The bare inside the quotes is meant to prevent related processes like systemd-journald from showing upwardly in the list.

$ ps -ef | grep "systemd " | grep -v grep root    ane   0 0 Jul17 ?    00:00:59 /usr/lib/systemd/systemd --system --deserialize xxx gdm  1244   1 0 Jul17 ?    00:00:00 /usr/lib/systemd/systemd --user shs  5429   1 0 Jul19 ?    00:00:00 /usr/lib/systemd/systemd --user              

The first process listed (with --system) is the primary systemd process. The 2d and tertiary are managing user (--user) sessions. In this case, one is associated with the GNOME display director (gdm) and the other with a logged-in user.

If you look at all running systemd processes, y'all're likely to see these. Each plays a role in managing organization services. For case, organisation-journald collects and stores logging data.

/usr/lib/systemd/systemd /usr/lib/systemd/systemd-journald /usr/lib/systemd/systemd-udevd /usr/lib/systemd/systemd-oomd /usr/lib/systemd/systemd-resolved /usr/lib/systemd/systemd-homed /usr/lib/systemd/systemd-machined /usr/lib/systemd/systemd-logind /usr/lib/systemd/systemd-userdbd /usr/lib/systemd/systemd systemd-userwork              

To view or control systemd services, use the systemctl control. You tin can view running processes with a command like this:

$ systemctl | head -1; systemctl | grep running | head -11  Unit of measurement                               LOAD   ACTIVE SUB       Description  proc-sys-fs-binfmt_misc.automount  loaded agile running   Arbitrary Executable File Formats File System  cups.path                          loaded active running   CUPS Scheduler  init.scope                         loaded active running   System and Service Managing director  session-xiii.scope                   loaded active running   Session 13 of User shs  session-6.scope                    loaded agile running   Session 6 of User shs  session-c1.scope                   loaded active running   Session c1 of User gdm  abrt-journal-core.service          loaded active running   Creates ABRT issues from coredumpctl letters  abrt-oops.service                  loaded active running   ABRT kernel log watcher  abrt-xorg.service                  loaded active running   ABRT Xorg log watcher  abrtd.service                      loaded active running   ABRT Automated Bug Reporting Tool  accounts-daemon.service            loaded active running   Accounts Service              

I added thesystemctl | head -1 in the command to a higher place to provide column headings.

For systemd, the word "UNIT" refers to whatsoever resources that the system knows how to operate and manage. To list those that are enabled, y'all tin use a control like this:

$ systemctl listing-unit-files --state=enabled | head -xv
UNIT FILE STATE VENDOR PRESET
cups.path enabled enabled
abrt-journal-core.service enabled enabled
abrt-oops.service enabled enabled
abrt-vmcore.service enabled enabled
abrt-xorg.service enabled enabled
abrtd.service enabled enabled
accounts-daemon.service enabled enabled
atd.service enabled enabled
auditd.service enabled enabled
avahi-daemon.service enabled enabled
bluetooth.service enabled enabled
chronyd.service enabled enabled
crond.service enabled enabled
cups.service enabled disabled

Note that "enabled" doesn't mean that a service is running. And "running" doesn't necessarily mean that it'due south enabled. Each means something different. "Enabled" means that the organisation volition run the service on the next kicking (whether or not it's running now). Once you enable a service, you however demand to manually first it if y'all desire it to run correct away, or yous tin reboot the system and it will start automatically.

The "running" status means that the process is actually running. If it'southward non as well enabled, information technology won't restart when you reboot.

In the commands below, we tin can see that the web service is both enabled and running:

$ systemctl list-unit of measurement-files | head -ane; systemctl list-unit-files | grep http UNIT FILE                        STATE           VENDOR PRESET httpd.service                    enabled         disabled                <== enabled                httpd@.service                   disabled        disabled httpd.socket                     disabled        disabled  $ systemctl | grep running | grep http   httpd.service     loaded active running   The Apache HTTP Server                <== running                              

You tin view a lot more information related to this service past asking for its condition:

$ systemctl status httpd.service ● httpd.service - The Apache HTTP Server      Loaded: loaded (/usr/lib/systemd/organization/httpd.service; enabled; vendor preset: disabled)      Active: agile (running) since Sabbatum 2021-07-17 eighteen:21:44 EDT; 1 week 1 24-hour interval agone        Docs: human:httpd.service(8)    Primary PID: 876 (httpd)      Status: "Full requests: 154; Idle/Busy workers 100/0;Requests/sec: 0.000204; Bytes served/sec:   0 B/sec"       Tasks: 213 (limit: 7072)      Memory: 20.3M         CPU: 1min 58.761s      CGroup: /system.slice/httpd.service              ├─   876 /usr/sbin/httpd -DFOREGROUND              ├─394234 /usr/sbin/httpd -DFOREGROUND              ├─394235 /usr/sbin/httpd -DFOREGROUND              ├─394236 /usr/sbin/httpd -DFOREGROUND              └─394237 /usr/sbin/httpd -DFOREGROUND  Jul 25 00:00:07 dragonfly systemd[1]: Reloaded The Apache HTTP Server. Jul 25 00:00:08 dragonfly httpd[876]: Server configured, listening on: port 80              

Alternately, you can merely determine whether a particular service is active and/or enabled with commands like these:

$ systemctl is-agile httpd.service Agile $ systemctl is-enabled httpd.service Enabled              

Wrap-upwardly

The systemctl command provides different details on system processes than the ps command. Where ps just lists processes which are running, systemctl lists which services are known, which can be managed by systemd and whether services are enabled.

Join the Network Earth communities on Facebook and LinkedIn to comment on topics that are top of heed.

Copyright © 2021 IDG Communications, Inc.