brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemd-analyze log-level debug makes systemd itself log in detail

Systemd
~/tips/tip-systemd-analyze-log-level

sudo systemd-analyze log-level debug

Turn on debug logging for the service manager at runtime, without a reboot.

When a unit does something I can not explain, like starting in the wrong order or getting stopped for no reason, the normal log is too quiet. PID 1 can tell a lot more.

Change the log level of the running service manager:

sudo systemd-analyze log-level debug
sudo systemctl restart myapp.service
journalctl _PID=1 -n 100

systemd-analyze log-level without an argument prints the current level, usually info, and after setting it, debug. From then on PID 1 logs every job it queues, every dependency it pulls in, and why it decides to start or stop something.

Turn it back when you are done:

sudo systemd-analyze log-level info

The change only lasts until the next reboot, which I like; you can not forget it on forever. For debugging from the very start of boot, put systemd.log_level=debug on the kernel command line instead.

Debug output from PID 1 is a lot. On a busy server it can push hundreds of lines per second into the journal, rotate older logs away and trip rate limits. Turn it on, reproduce the problem, and switch it off within minutes.

Further reading: systemd-analyze man page, systemd man page (log level)

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link