]> git.ipfire.org Git - thirdparty/systemd.git/blame - docs/TIPS_AND_TRICKS.md
docs: use absolute links for our pages
[thirdparty/systemd.git] / docs / TIPS_AND_TRICKS.md
CommitLineData
6b2a2776 1---
2title: Tips And Tricks
3category: Manuals and Documentation for Users and Administrators
4layout: default
5SPDX-License-Identifier: LGPL-2.1-or-later
6---
7
8# Tips & Tricks
9
0d592a5e 10Also check out the [Frequently Asked Questions](/FAQ)!
6b2a2776 11
12## Listing running services
13
14```sh
15$ systemctl
16UNIT LOAD ACTIVE SUB JOB DESCRIPTION
17accounts-daemon.service loaded active running Accounts Service
18atd.service loaded active running Job spooling tools
19avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack
20bluetooth.service loaded active running Bluetooth Manager
21colord-sane.service loaded active running Daemon for monitoring attached scanners and registering them with colord
22colord.service loaded active running Manage, Install and Generate Color Profiles
23crond.service loaded active running Command Scheduler
24cups.service loaded active running CUPS Printing Service
25dbus.service loaded active running D-Bus System Message Bus
26...
27```
28
29## Showing runtime status
30
31```sh
32$ systemctl status udisks2.service
33udisks2.service - Storage Daemon
34 Loaded: loaded (/usr/lib/systemd/system/udisks2.service; static)
35 Active: active (running) since Wed, 27 Jun 2012 20:49:25 +0200; 1 day and 1h ago
36 Main PID: 615 (udisksd)
37 CGroup: name=systemd:/system/udisks2.service
38 └ 615 /usr/lib/udisks2/udisksd --no-debug
39
40Jun 27 20:49:25 epsilon udisksd[615]: udisks daemon version 1.94.0 starting
41Jun 27 20:49:25 epsilon udisksd[615]: Acquired the name org.freedesktop.UDisks2 on the system message bus
42```
43
44## cgroup tree
45
46```sh
47$ systemd-cgls
48└ system
49├ 1 /usr/lib/systemd/systemd --system --deserialize 18
50├ ntpd.service
51│ └ 8471 /usr/sbin/ntpd -u ntp:ntp -g
52├ upower.service
53│ └ 798 /usr/libexec/upowerd
54├ wpa_supplicant.service
55│ └ 751 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid
56├ nfs-idmap.service
57│ └ 731 /usr/sbin/rpc.idmapd
58├ nfs-rquotad.service
59│ └ 753 /usr/sbin/rpc.rquotad
60├ nfs-mountd.service
61│ └ 732 /usr/sbin/rpc.mountd
62├ nfs-lock.service
63│ └ 704 /sbin/rpc.statd
64├ rpcbind.service
65│ └ 680 /sbin/rpcbind -w
66├ postfix.service
67│ ├ 859 /usr/libexec/postfix/master
68│ ├ 877 qmgr -l -t fifo -u
69│ └ 32271 pickup -l -t fifo -u
70├ colord-sane.service
71│ └ 647 /usr/libexec/colord-sane
72├ udisks2.service
73│ └ 615 /usr/lib/udisks2/udisksd --no-debug
74├ colord.service
75│ └ 607 /usr/libexec/colord
76├ prefdm.service
77│ ├ 567 /usr/sbin/gdm-binary -nodaemon
78│ ├ 602 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManager/Display1
79│ ├ 612 /usr/bin/Xorg :0 -br -verbose -auth /var/run/gdm/auth-for-gdm-O00GPA/database -seat seat0 -nolisten tcp
80│ └ 905 gdm-session-worker [pam/gdm-password]
81├ systemd-ask-password-wall.service
82│ └ 645 /usr/bin/systemd-tty-ask-password-agent --wall
83├ atd.service
84│ └ 544 /usr/sbin/atd -f
85├ ksmtuned.service
86│ ├ 548 /bin/bash /usr/sbin/ksmtuned
87│ └ 1092 sleep 60
88├ dbus.service
89│ ├ 586 /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation
90│ ├ 601 /usr/libexec/polkit-1/polkitd --no-debug
91│ └ 657 /usr/sbin/modem-manager
92├ cups.service
93│ └ 508 /usr/sbin/cupsd -f
94├ avahi-daemon.service
95│ ├ 506 avahi-daemon: running [epsilon.local]
96│ └ 516 avahi-daemon: chroot helper
97├ system-setup-keyboard.service
98│ └ 504 /usr/bin/system-setup-keyboard
99├ accounts-daemon.service
100│ └ 502 /usr/libexec/accounts-daemon
101├ systemd-logind.service
102│ └ 498 /usr/lib/systemd/systemd-logind
103├ crond.service
104│ └ 486 /usr/sbin/crond -n
105├ NetworkManager.service
106│ ├ 484 /usr/sbin/NetworkManager --no-daemon
107│ └ 8437 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-wlan0.pid -lf /var/lib/dhclient/dhclient-903b6f6aa7a1-46c8-82a9-7f637dfbb3e4-wlan0.lease -cf /var/run/nm-d...
108├ libvirtd.service
109│ ├ 480 /usr/sbin/libvirtd
110│ └ 571 /sbin/dnsmasq --strict-order --bind-interfaces --pid-file=/var/run/libvirt/network/default.pid --conf-file= --except-interface lo --listenaddress 192.168.122.1 --dhcp-range 192.168.122.2,1...
111├ bluetooth.service
112│ └ 479 /usr/sbin/bluetoothd -n
113├ systemd-udev.service
114│ └ 287 /usr/lib/systemd/systemd-udevd
115└ systemd-journald.service
116└ 280 /usr/lib/systemd/systemd-journald
117```
118
119### ps with cgroups
120
121```sh
122$ alias psc='ps xawf -eo pid,user,cgroup,args'
123$ psc
124 PID USER CGROUP COMMAND
125...
126 1 root name=systemd:/systemd-1 /bin/systemd systemd.log_target=kmsg systemd.log_level=debug selinux=0
127 415 root name=systemd:/systemd-1/sysinit.service /sbin/udevd -d
128 928 root name=systemd:/systemd-1/atd.service /usr/sbin/atd -f
129 930 root name=systemd:/systemd-1/ntpd.service /usr/sbin/ntpd -n
130 932 root name=systemd:/systemd-1/crond.service /usr/sbin/crond -n
131 935 root name=systemd:/systemd-1/auditd.service /sbin/auditd -n
132 943 root name=systemd:/systemd-1/auditd.service \_ /sbin/audispd
133 964 root name=systemd:/systemd-1/auditd.service \_ /usr/sbin/sedispatch
134 937 root name=systemd:/systemd-1/acpid.service /usr/sbin/acpid -f
135 941 rpc name=systemd:/systemd-1/rpcbind.service /sbin/rpcbind -f
136 944 root name=systemd:/systemd-1/rsyslog.service /sbin/rsyslogd -n -c 4
137 947 root name=systemd:/systemd-1/systemd-logger.service /lib/systemd/systemd-logger
138 950 root name=systemd:/systemd-1/cups.service /usr/sbin/cupsd -f
139 955 dbus name=systemd:/systemd-1/messagebus.service /bin/dbus-daemon --system --address=systemd: --nofork --systemd-activation
140 969 root name=systemd:/systemd-1/getty@.service/tty6 /sbin/mingetty tty6
141 970 root name=systemd:/systemd-1/getty@.service/tty5 /sbin/mingetty tty5
142 971 root name=systemd:/systemd-1/getty@.service/tty1 /sbin/mingetty tty1
143 973 root name=systemd:/systemd-1/getty@.service/tty4 /sbin/mingetty tty4
144 974 root name=systemd:/user/lennart/2 login -- lennart
145 1824 lennart name=systemd:/user/lennart/2 \_ -bash
146 975 root name=systemd:/systemd-1/getty@.service/tty3 /sbin/mingetty tty3
147 988 root name=systemd:/systemd-1/polkitd.service /usr/libexec/polkit-1/polkitd
148 994 rtkit name=systemd:/systemd-1/rtkit-daemon.service /usr/libexec/rtkit-daemon
149...
150```
151
152## Changing the Default Boot Target
153
154```sh
155$ ln -sf /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target
156```
157
56a0f583 158This line makes the multi user target (i.e. full system, but no graphical UI) the default target to boot into.
159This is kinda equivalent to setting runlevel 3 as the default runlevel on Fedora/sysvinit systems.
6b2a2776 160
161```sh
162$ ln -sf /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target
163```
164
56a0f583 165This line makes the graphical target (i.e. full system, including graphical UI) the default target to boot into.
166Kinda equivalent to runlevel 5 on fedora/sysvinit systems.
167This is how things are shipped by default.
6b2a2776 168
169## What other units does a unit depend on?
170
171For example, if you want to figure out which services a target like multi-user.target pulls in, use something like this:
172
173```sh
174$ systemctl show -p "Wants" multi-user.target
175Wants=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
176```
177
56a0f583 178Instead of "Wants" you might also try "WantedBy", "Requires", "RequiredBy", "Conflicts", "ConflictedBy", "Before", "After"
179for the respective types of dependencies and their inverse.
6b2a2776 180
181## What would get started if I booted into a specific target?
182
183If you want systemd to calculate the "initial" transaction it would execute on boot, try something like this:
184
185```sh
186$ systemd --test --system --unit=foobar.target
187```
188
56a0f583 189for a boot target foobar.target.
190Note that this is mostly a debugging tool that actually does a lot more than just calculate the initial transaction,
191so don't build scripts based on this.