systemd¶
🤷♂️
analyze slow boot times¶
list how long it took for systemd units to initialize:
output example:
DNS¶
all things DNS
change dns resolver¶
get current status and dns server:
change to another DNS server:
edit /etc/systemd/resolved.conf
and change the DNS
line. for example:
if you want to use DNS over TLS:
restart service:
verify again (see above)
change hostname¶
depending on your setup you might still need to update your /etc/hosts
file as well
clear dns cache¶
verify:
logs: journalctl / systemd journals¶
read journalctl logs / syslog¶
the following flags can usually be combined, so -f -u <service>
works as well.
follow all new logs (tail -f):
display last 100 lines and follow new logs:
read logs from a specific service/unit:
configure journal / log usage¶
it might be a good idea to limit the disk usage of your systemd journals. To do this, edit the file: /etc/systemd/journald.conf
control how much disk space the journal may use up at most:
control how large individual journal files may grow at most:
and restart things
log disk usage¶
check current disk usage of systemd journals:
clean up some old logs:
timers (better cronjobs!)¶
todo.. write something somewhere about the use of systemd-timers instead of cronjobs.
create your own timer / cronjob¶
create your service unit:
place it somewhere in /etc/systemd/system/restic_backup.service
for example
[Unit]
Description=restic systemd service
[Service]
ExecStart=/usr/local/bin/backup.sh
[Install]
WantedBy=multi-user.target
create your timer:
place it in the same folder but name it .timer
, like this: /etc/systemd/system/restic_backup.timer
[Unit]
Description=restic systemd timer
[Timer]
OnUnitActiveSec=24h
RandomizedDelaySec=1h
[Install]
WantedBy=multi-user.target
there are many different ways when the service should run, like with OnUnitActiveSec
every 24 hours including a randomized delay of 1h.
here's the documentation for more ways when system should execute something
reload and enable the service:
disable timer¶
list timers¶
remove / clear dead or dangling timers¶
I removed a service and timer through ansible and reloaded systemd, but the timer was still showing up when running systemd list-timers
. This worked to clean it up:
working with services¶
debugging: read and follow service logs output¶
read logs:
tail log:
disable / mask service, prevent from starting & unmask¶
using disable stops the service from starting automatically, but it can be started manually. mask prevents the service from being started at all by creating a symlink to /dev/null
list masked services:
disable a service from starting automatically:
it can be started manually, for example by NetworkManager
prevent service from being started at all:
the output will also tell you that the service has been linked to /dev/null
:
list active services¶
the service might be active, but exited already since it was just initializing or checking something