Skip to content

systemd

"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/

Tips

Init file locations

/usr/lib/systemd/system
/etc/systemd/system # has precedence

Show the full systemd journal

The systemd journal is syslog and more.

journalctl --full

Show the nginx journal for today

The -u here is "unit", not "user".

journalctl -u nginx.service --since today

List journals by boot

journalctl --list-boots

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

Show timers

"A unit configuration file whose name ends in ".timer" encodes information about a timer controlled and supervised by systemd, for timer-based activation." - man systemd.timer

systemctl list-timers

Show units

Units are things that are handled by systemd, including services. systemctl list-units

Show dependencies

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

Per-user services

https://wiki.archlinux.org/index.php/Systemd/User

/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

/etc/systemd/logind.conf

Show name resolution status

systemd-resolve --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

systemd-cgls

Show top control groups by their resource usage

systemd-cgtop

Detect if you are running in a container or on a VM

systemd-detect-virt