Systemd
Contents
About
Migration from /lib to /usr/lib
With the migration of SystemD from /lib to /usr/lib some links may be broken.
1 find /etc/systemd -xtype l -exec ls -l --color=always {} \;
These broken links can be regenerated by disabling and enabling them. Here's a naive fix.
Analyse targets
These commands may reveal some configuration problems like boot-loops
Some common commands
List enabled/disabled units
This is quite useful
1 systemctl list-unit-files
Just a note for SystemV
sysv-rc-conf
update-rc.d
Enable/disable units
View unit-definitions
1 systemctl cat smbd.service
Journal
- Checking the logs is a essential part a sysadmins every-day work
- man-pages
1 journalctl -xn40
List failed units
1 systemctl --failed
systemd-resolved
Network Name Resolution manager
systemd-resolved is a system service that provides network name resolution to local applications. It implements a caching and validating DNS/DNSSEC stub resolver, as well as an LLMNR and MulticastDNS resolver and responder.
3 interfaces:
- native, fully-featured API on the bus
- The glibc getaddrinfo(3) API as defined by RFC3493[1]
DNS stub resolver listening on 127.0.0.53 on the loopback interface
Man pages
systemd-resolved is enabled, you may use.
1 resolvectl status
/etc/systemd/resolved.conf
1 # This file is part of systemd.
2 #
3 # systemd is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU Lesser General Public License as published by
5 # the Free Software Foundation; either version 2.1 of the License, or
6 # (at your option) any later version.
7 #
8 # Entries in this file show the compile time defaults.
9 # You can change settings by editing this file.
10 # Defaults can be restored by simply deleting this file.
11 #
12 # See resolved.conf(5) for details
13
14 [Resolve]
15 #DNS=
16 #FallbackDNS=
17 #Domains=
18 #LLMNR=yes
19 #MulticastDNS=yes
20 #DNSSEC=allow-downgrade
21 #DNSOverTLS=no
22 #Cache=yes
23 #DNSStubListener=yes
24 #ReadEtcHosts=yes
modes
systemd-resolved has for modes for /etc/hosts, which is detected automatically.
Please see:
man -P "less -p '/ETC/RESOLV.CONF'" systemd-resolved
stub, static, uplink, foreign
stub (recommended)
/etc/resolv.conf is a link on /run/systemd/resolv/stub-resolv.conf
static
/usr/lib/systemd/resolv.conf exists and /etc/resolv.conf may be a link on this file for compatibility. There is no "search-domains".
uplink
/etc/resolv.conf is a link on /run/systemd/resolve/resolv.conf
foreign
/etc/resolv.conf is a file, which is managed by other packages or is simply static.
To change the behavior to the recommended behavior stub you may:
A reboot is not necessary.
bootcharts
systemd-analyse
Create a bootchart /root/systemd_boot.sh
1 #!/bin/bash
2 DATE="$(date +%F_%T)"
3 GRAPH_PATH="/run/log"
4 GRAPH_FILE="systemd-analyse_plot_${DATE}.svg"
5 GRAPH="$GRAPH_PATH/$GRAPH_FILE"
6 GRAPH_LATEST="$GRAPH_PATH/systemd-analyse_plot_latest.svg"
7 systemd-analyze plot > "$GRAPH"
8 [[ -f "$GRAPH_LATEST" ]] && unlink "$GRAPH_LATEST"
9 ln -s "$GRAPH" "$GRAPH_LATEST"
10 cat <<-EOF
11 file://$GRAPH_LATEST
12 file://$GRAPH
13 EOF
file:///run/log/systemd-analyse_plot_latest.svg
It makes sense to open it with a browser to be able to search the graph with CTRL+F.
systemd-bootchart
Install
1 aptitude install systemd-bootchart
Reboot
ll -a /run/log/
tmpfiles.d
man systemd-tmpfiles
man tmpfiles.d
/etc/tmpfiles.d/pdf.conf
There are two related systemd-services and units like timers:
systemd-tmpfiles-setup.service
systemd-tmpfiles-clean.service
It's worth a look if the setup was successful. In my case I messed up the group name …
1 # systemctl status systemd-tmpfiles-setup.service
2 ● systemd-tmpfiles-setup.service - Create Volatile Files and Directories
3 Loaded: loaded (/lib/systemd/system/systemd-tmpfiles-setup.service; static)
4 Active: active (exited) since Wed 2023-12-06 10:19:19 CET; 23min ago
5 Docs: man:tmpfiles.d(5)
6 man:systemd-tmpfiles(8)
7 Process: 1578 ExecStart=systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev (code=exited, status=65)
8 Main PID: 1578 (code=exited, status=65)
9 CPU: 26ms
10
11 Dez 06 10:19:19 fuxtop systemd[1]: Starting systemd-tmpfiles-setup.service - Create Volatile Files and Directories...
12 Dez 06 10:19:19 fuxtop systemd-tmpfiles[1578]: /etc/tmpfiles.d/pdf.conf:2: Failed to resolve group 'nobody'.
13 Dez 06 10:19:19 fuxtop systemd[1]: Finished systemd-tmpfiles-setup.service - Create Volatile Files and Directories.
The execution may be forced at runtime with
1 systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev
systemd.timers
Please see:
man 5 systemd.timer for the specification of the timer-unit
man 7 systemd.time for the specification of the time used in OnCalendar
Validate your time-spec wit systemd-analyse
1 $ systemd-analyze calendar daily
2 Original form: daily
3 Normalized form: *-*-* 00:00:00
4 Next elapse: Sat 2024-05-18 00:00:00 CEST
5 (in UTC): Fri 2024-05-17 22:00:00 UTC
6 From now: 14h left
7 $ systemd-analyze calendar '*-*-* 08:00:00'
8 Normalized form: *-*-* 08:00:00
9 Next elapse: Sat 2024-05-18 08:00:00 CEST
10 (in UTC): Sat 2024-05-18 06:00:00 UTC
11 From now: 22h left