Tips & Tricks
Also check out the Frequently Asked Questions!
Listing running services
$ systemctl UNIT LOAD ACTIVE SUB JOB DESCRIPTION messagebus.service loaded active running messagebus.service basic.target loaded active active Basic System sysinit.target loaded active active Systemd Initialization local-fs.target loaded active active Local File Systems swap.target loaded active active Swap sockets.target loaded active active Sockets ...
Showing runtime status
$ systemctl status udisks.service
udisks.service - udisks Disk Manager
Loaded: loaded (/etc/systemd/system/multi-user.target.wants/../udisks.service)
Active: active (running)
Process: 999 (udisks-daemon)
CGroup: name=systemd:/systemd-1/udisks.service
│
├ 999 /usr/libexec/udisks-daemon
├ 1018 udisks-daemon: polling /dev/sr0
└ 1132 /usr/libexec/udisks-daemon
cgroup tree
The tree tool is very handy to list the tree of control groups:
$ tree -d /cgroup/systemd/
/cgroup/systemd/
├── systemd-1
│ ├── abrtd.service
│ ├── accounts-daemon.service
│ ├── acpid.service
...
│ ├── crond.service
│ ├── cups.service
│ ├── getty@.service
│ │ ├── tty1
│ │ ├── tty3
│ │ ├── tty4
│ │ ├── tty5
│ │ └── tty6
│ ├── haldaemon.service
│ ├── mdmonitor.service
│ ├── messagebus.service
...
│ ├── udisks.service
│ ├── upowerd.service
│ └── wpa_supplicant.service
└── user
└── lennart
├── 1
└── 2
38 directories
ps with cgroups
$ alias psc='ps xawf -eo pid,user,cgroup,args'
$ psc
PID USER CGROUP COMMAND
...
1 root name=systemd:/systemd-1 /bin/systemd systemd.log_target=kmsg systemd.log_level=debug selinux=0
415 root name=systemd:/systemd-1/sysinit.service /sbin/udevd -d
928 root name=systemd:/systemd-1/atd.service /usr/sbin/atd -f
930 root name=systemd:/systemd-1/ntpd.service /usr/sbin/ntpd -n
932 root name=systemd:/systemd-1/crond.service /usr/sbin/crond -n
935 root name=systemd:/systemd-1/auditd.service /sbin/auditd -n
943 root name=systemd:/systemd-1/auditd.service \_ /sbin/audispd
964 root name=systemd:/systemd-1/auditd.service \_ /usr/sbin/sedispatch
937 root name=systemd:/systemd-1/acpid.service /usr/sbin/acpid -f
941 rpc name=systemd:/systemd-1/rpcbind.service /sbin/rpcbind -f
944 root name=systemd:/systemd-1/rsyslog.service /sbin/rsyslogd -n -c 4
947 root name=systemd:/systemd-1/systemd-logger.service /lib/systemd/systemd-logger
950 root name=systemd:/systemd-1/cups.service /usr/sbin/cupsd -f
955 dbus name=systemd:/systemd-1/messagebus.service /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation
969 root name=systemd:/systemd-1/getty@.service/tty6 /sbin/mingetty tty6
970 root name=systemd:/systemd-1/getty@.service/tty5 /sbin/mingetty tty5
971 root name=systemd:/systemd-1/getty@.service/tty1 /sbin/mingetty tty1
973 root name=systemd:/systemd-1/getty@.service/tty4 /sbin/mingetty tty4
974 root name=systemd:/user/lennart/2 login -- lennart
1824 lennart name=systemd:/user/lennart/2 \_ -bash
975 root name=systemd:/systemd-1/getty@.service/tty3 /sbin/mingetty tty3
988 root name=systemd:/systemd-1/polkitd.service /usr/libexec/polkit-1/polkitd
994 rtkit name=systemd:/systemd-1/rtkit-daemon.service /usr/libexec/rtkit-daemon
...
Changing the Default Boot Target
$ ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
This line makes the multi user target (i.e. full system, but no graphical UI) the default target to boot into. This is kinda equivalent to setting runlevel 3 as the default runlevel on Fedora/sysvinit systems.
$ ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
This line makes the graphical target (i.e. full system, including graphical UI) the default target to boot into. Kinda equivalent to runlevel 5 on fedora/sysvinit systems. This is how things are shipped by default.
cgroup tree
$ systemd-cgls
├ 2 [kthreadd]
[...]
├ 29167 [flush-253:0]
├ user
│ └ lennart
│ ├ 39
│ │ ├ 29075 sshd: lennart [priv]
│ │ ├ 29079 sshd: lennart@pts/0
│ │ ├ 29080 -bash
│ │ └ 29168 systemd-cgls
│ └ 1
│ ├ 1141 login -- lennart
│ ├ 1532 -bash
│ ├ 1615 ssh-agent
│ └ 1641 gpg-agent --daemon --write-env-file
└ systemd-1
├ 1 /bin/systemd systemd.log_target=kmsg systemd.log_level=debug selinux=0
├ sshd@.service
│ └ 4
├ prefdm.service
│ └ 1272 /usr/sbin/gdm-binary -nodaemon
├ systemd-logger.service
│ └ 1162 /lib/systemd/systemd-logger
├ getty@.service
│ ├ tty3
│ │ └ 1148 /sbin/mingetty tty3
│ ├ tty2
│ ├ tty4
│ │ └ 1136 /sbin/mingetty tty4
│ ├ tty5
│ │ └ 1132 /sbin/mingetty tty5
│ └ tty6
│ └ 1125 /sbin/mingetty tty6
├ mdmonitor.service
│ └ 1194 mdadm --monitor --scan -f --pid-file=/var/run/mdadm/mdadm.pid
├ irqbalance.service
│ └ 1171 irqbalance
├ sendmail.service
│ ├ 1430 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
│ └ 1434 sendmail: accepting connections
├ accounts-daemon.service
│ └ 994 /usr/libexec/accounts-daemon
├ polkitd.service
│ └ 986 /usr/libexec/polkit-1/polkitd
├ wpa_supplicant.service
│ └ 981 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u
├ bluetooth.service
│ └ 980 /usr/sbin/bluetoothd -n
├ udisks.service
│ ├ 978 /usr/libexec/udisks-daemon
│ └ 993 udisks-daemon: polling /dev/sr0
├ dbus.service
│ └ 1010 /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation
├ auditd.service
│ ├ 975 /sbin/auditd -n
│ ├ 988 /sbin/audispd
│ └ 997 /usr/sbin/sedispatch
├ console-kit-daemon.service
│ └ 971 /usr/sbin/console-kit-daemon --no-daemon
├ rsyslog.service
│ └ 969 /sbin/rsyslogd -n -c 4
├ rtkit-daemon.service
│ └ 968 /usr/libexec/rtkit-daemon
├ haldaemon.service
│ ├ 967 /usr/sbin/hald --daemon=no --use-syslog
│ ├ 1014 hald-runner
│ ├ 1275 hald-addon-input: Listening on /dev/input/event3 /dev/input/event7 /dev/input/event6 /dev/input/event1 /dev/input/event4 /dev/input/event2 /dev/input/event0 /dev/input/event9
│ ├ 1281 /usr/libexec/hald-addon-rfkill-killswitch
│ ├ 1299 /usr/libexec/hald-addon-leds
│ ├ 1301 /usr/libexec/hald-addon-generic-backlight
│ └ 1308 /usr/libexec/hald-addon-acpi
├ upowerd.service
│ └ 966 /usr/libexec/upowerd
├ abrtd.service
│ └ 963 /usr/sbin/abrtd -d -s
├ rpcbind.service
│ └ 961 /sbin/rpcbind -f
├ cups.service
│ └ 1005 /usr/sbin/cupsd -f
├ modem-manager.service
│ └ 955 /usr/sbin/modem-manager
├ crond.service
│ └ 951 /usr/sbin/crond -n
├ atd.service
│ └ 950 /usr/sbin/atd -f
├ acpid.service
│ └ 949 /usr/sbin/acpid -f
├ NetworkManager.service
│ ├ 946 /usr/sbin/NetworkManager --no-daemon
│ └ 1319 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth0.pid -lf /var/lib/dhclient/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease -cf /var/run/nm-dhclient-eth0.conf eth0
├ avahi-daemon.service
│ ├ 944 avahi-daemon: running [lambda.local]
│ └ 957 avahi-daemon: chroot helper
├ hdapsd@.service
│ └ sda
│ └ 940 /usr/sbin/hdapsd -d sda
├ dev-mqueue.mount
├ dev-hugepages.mount
└ sysinit.service
├ 414 /sbin/udevd -d
├ 468 /sbin/udevd -d
└ 469 /sbin/udevd -d
What other units does a unit depend on?
For example, if you want to figure out which services a target like multi-user.target pulls in, use something like this:
$ systemctl show -p "Wants" multi-user.target Wants=rc-local.service avahi-daemon.service rpcbind.service NetworkManager.service acpid.service dbus.service atd.service crond.service auditd.service ntpd.service udisks.service bluetooth.service cups.service wpa_supplicant.service getty.target modem-manager.service portreserve.service abrtd.service yum-updatesd.service upowerd.service test-first.service pcscd.service rsyslog.service haldaemon.service remote-fs.target plymouth-quit.service systemd-update-utmp-runlevel.service sendmail.service lvm2-monitor.service cpuspeed.service udev-post.service mdmonitor.service iscsid.service livesys.service livesys-late.service irqbalance.service iscsi.service netfs.service
Instead of "Wants" you might also try "WantedBy", "Requires", "RequiredBy", "Conflicts", "ConflictedBy", "Before", "After" for the respective types of dependencies and their inverse.
What would get started if I booted into a specific target?
If you want systemd to calculate the "initial" transaction it would execute on boot, try something like this:
$ systemd --test --system --unit=foobar.target
for a boot target foobar.target. Note that this is mostly a debugging tool that actually does a lot more than just calculate the initial transaction, so don't build scripts based on this.


