Linux - systemd


useful commands

systemctl

journalctl

useful options:

NOTE: be cautious when using -e and -n options: they might cause some lines not to be printed.

view recent entries with explanation messages:

$ journalctl -xn

view journal for specified unit:

$ journalctl -u my-player.service

view journal for multiple units at once (entries are merged in chronological order):

$ journalctl -u my-player.service -u my-player.socket

view journal for multiple units using wildcard:

$ journalctl -u my-*.service

view disk usage:

$ journalctl --disk-usage

creating custom unit file

tips

timer unit

if using timer for associated service, enable timer unit only - associated service unit will be activated when the timer is reached:

$ sudo systemctl enable foo.timer

socket unit

if using socket-based activation of the service, enable socket unit only - associated service unit will be activated when anything is written to socket:

$ sudo systemctl enable foo.socket

debugging

view service logs

service units in most cases redirect their standard output and standard error to systemd journal - this is where you, say, can find information why specific service failed to start.

there are several options to view systemd journal: