Linux Administration Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

At the command line, type the following:

$ systemctl

You should be dropped into a list of systemd units; this is a good initial overview of every unit systemd is aware of, but it's very noisy (as seen in the following screenshot) and what we specifically want to see are daemons (because of our gothic streak):

Services and daemons are somewhat interchangeable in Linux land; for example, systemd refers to daemons as service files. This doesn't stop some people from getting passionately angry about "proper usage".

Try the following:

$ systemctl list-units --type service

You should be given a list of services and their statuses.

This view is better, but it also shows failed and exited services, for example, on our Vagrant instance, we should see the following:

If I want to exclude these, I can use the following command:

$ systemctl list-units --type service --state running

Now we get a much more condensed list, with 17 items in total:

UNIT                     LOAD   ACTIVE SUB     DESCRIPTION
auditd.service loaded active running Security Auditing Service
chronyd.service loaded active running NTP client/server
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
getty@tty1.service loaded active running Getty on tty1
gssproxy.service loaded active running GSSAPI Proxy Daemon
lvm2-lvmetad.service loaded active running LVM2 metadata daemon
NetworkManager.service loaded active running Network Manager
polkit.service loaded active running Authorization Manager
postfix.service loaded active running Postfix Mail Transport Agent
rpcbind.service loaded active running RPC bind service
rsyslog.service loaded active running System Logging Service
sshd.service loaded active running OpenSSH server daemon
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-udevd.service loaded active running udev Kernel Device Manager
tuned.service loaded active running Dynamic System Tuning Daemon

LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.

17 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
You can get rid of the helpful-but-noisy header and footer notes with the --no-legend option to systemctl.