systemd

Table of Contents

1. systemctl

1.1. List

1.1.1. Services

systemctl # runnning
systemctl --failed # failed

1.1.2. Units

systemctl list-units # add filters if required (--all, --state, --type)
systemctl --state help # show state filters
systemctl --type help # show type filters

1.1.3. Others

systemctl list-dependencies <unit> # list dependencies of a unit

1.2. Operations

1.2.1. Common operations

systemctl {start,restart,reload,stop,status,enable,disable} foo.service

1.2.2. Debug operations

systemctl edit [unit]
systemctl show [unit] # list properties
systemctl cat  [unit] # list file

1.2.3. Restart

systemctl reset-failed [service_name] # reset failed restart
systemctl daemon-reload # reload daemons after unit file changes

1.3. User services

cat /usr/lib/systemd/user/emacs.service
systemctl --user status emacs.service # without --user this won't be shown

2. journalctl

2.1. Filters

journalctl -u [unit] -b # for some unit, for the most recent boot
journalctl -p 3 -b # list errors(see -p flag) of current boot
journalctl -rb -1 # Show logs of last boot in reverse order
journalctl -b # Show logs of last boot in reverse order
journalctl -f # follow log (like tail -f)
journalctl --since=2012-10-15 --until="2011-10-16 23:59:59" # To filter by time period:
journalctl /usr/bin/dbus-daemon # filters by executable name
journalctl _PID=123 # filters by pid
journalctl _COMM=sshd # filters by command
journalctl _UID=1000 # filters by specific user id
journalctl -k # filters only kernal messages
journalctl -k --grep="IN=.*OUT=.*" # view packets that were logged by iptables since the machine was last booted

2.2. Info about journals

journalctl -F _SYSTEMD_UNIT # list systemd units logged
journalctl --list-boots # list all available boots
journalctl --disk-usage # disk usage of all journal files

3. systemd-analyze

boot up inspection

systemd-analyze time # (default)
systemd-analyze plot > plot.svg # startup time plot
systemd-analyze blame # list running units ordered by time to init

4. systemd-resolved

4.1. Flush DNS cache

pkill -USR1 systemd-resolve # dump all cache into system log if needed
journalctl -u systemd-resolved > ~/resolved.txt # dump all logs + cache info into a file if needed
systemd-resolve --flush-caches # flush cache

4.2. Common operations

systemd-resolve --status

5. Other systemd tools

  • systemd-cgls : Show cgroup tree
  • systemd-cgtop : Show cgroup resource usage
  • hostnamectl : play w system hostname
  • localectl : system locale and keyboard layout
  • coredumpctl : TODO
  • systemd-delta : find overidden files

Created: 2024-07-16 Tue 16:44

Validate