"systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for sysvinit." - http://www.freedesktop.org/wiki/Software/systemd/
- https://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks: Tips and tricks
- https://man7.org/linux/man-pages/man5/systemd.resource-control.5.html: Man page for control groups
- https://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions: FAQ
- https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet: sysvinit to chkconfig
- https://wiki.ubuntu.com/SystemdForUpstartUsers: systemd for upstart users
- https://github.com/joehillen/sysz: fzf interface for systemd
Init file locations
/usr/lib/systemd/system /etc/systemd/system # has precedence
Show the full systemd journal
The systemd journal is syslog and more.
Show logs for the last 15 minutes
journalctl --since "-15 minutes"
Show logs for one service
Find your service with
journalctl --unit="docker.service" --since -5m
Show only logs that match a certain pattern
"PERL-compatible regular expressions are used. … If the pattern is all lowercase, matching is case insensitive. Otherwise, matching is case sensitive. This can be overridden with the --case-sensitive option" -
journalctl -g '\b(foo|bar)\b
Show the nginx journal for today
-u here is "unit", not "user".
journalctl -u nginx.service --since today
List journals by boot
The above command produces the following style of output:
-5 e6fcef265a164688b5f9aad999a9b1d2 Mon 2019-09-09 08:55:47 PDT—Tue 2019-09-17 17:41:25 PDT -4 1e402042ad0a48bebe17298fd80dfb66 Tue 2019-09-17 17:42:06 PDT—Tue 2019-09-17 18:26:28 PDT -3 1b36653fa7b64b1a808f10a894a0e303 Tue 2019-09-17 18:27:11 PDT—Sun 2019-09-22 13:34:59 PDT -2 be854ba422934cf2a9e7952dc052461a Sun 2019-09-22 16:23:43 PDT—Mon 2019-09-30 07:55:08 PDT -1 0454f1208e5e49c59fabf95cf4f68346 Mon 2019-09-30 07:55:51 PDT—Fri 2019-10-04 08:54:38 PDT 0 f8c09c85ed9f4976987121a345b6f446 Fri 2019-10-04 08:55:22 PDT—Wed 2019-10-09 15:34:01 PDT
Show journal for previous boot
Using the info from the previous --list-boots example, we can view the system log for the previous boot. This gives all system logs from the time the system booted to the time it shut down.
journalctl -b -1 journalctl -b 0454f1208e5e49c59fabf95cf4f68346
"A unit configuration file whose name ends in ".timer" encodes information about a timer controlled and supervised by systemd, for timer-based activation." -
Units are things that are handled by systemd, including services.
This works on any .target or .service
systemctl list-dependencies network.service
Enable a service
This behavior replaces chkconfig
systemctl enable docker.service
Check the status of a service and show 20 lines
systemctl -n 20 status nodejs
/usr/lib/systemd/user/ # where services provided by installed packages go. /etc/systemd/user/ # where system-wide user services are placed by the system administrator. ~/.config/systemd/user/ # where the user puts its own services.
Alter power / sleep / hibernate button behaviors
Show name resolution status
Show boot performance
systemd-analyze blame systemd-analyze critical-chain
View a time-chart of the boot sequence
sudo systemd-analyze plot > systemd.svg
Show cgroup contexts
Show top control groups by their resource usage
Detect if you are running in a container or on a VM