systemd
# Basics of units/unit files:
• These are the basic objects that systemd manages.
• Unit types vary and are typically designated by their suffixes.
◦ .service for service files.
◦ .target for sync point between units when booting up or state changes.
◦ .mount for mount points.
◦ .timer for timers that can be used similarly to cron jobs.
◦ .socket, .device, .automount, .swap, .path, .snapshot, .slice, .scope, ...
• Unit files are broken down to section designations followed by key-value
pairs, for example:
◦ `[section]
Directive01=value
Directive02=value
...`
• Boolean values are flexible.
◦ 1, true, on, yes
◦ 0, false, off, no
• Unit sections are clearly defined.
◦ See `man systemd.unit` for general unit file details.
◦ See `man systemd.service`, `man systemd.timer`, etc. for specific details.
# Working with units:
• Listing units:
◦ `systemctl` or `systemctl list-units` # This will list all systemd units.
◦ `systemctl -t ` # This will limit list to service of ‘’.
• Status of unit:
◦ `systemctl status `
• Starting unit:
◦ `systemctl start `
• Stopping unit:
◦ `systemctl stop `
• Restarting unit:
◦ `systemctl restart `
• Reloading unit configuration:
◦ `systemctl reload `
• Enabling unit at boot time:
◦ `systemctl enable `
• Disabling unit at boot time:
◦ `systemctl disable `
• Check if unit is enabled at boot time (status shows this as well):
◦ `systemctl is-enabled ` # returns 0/1 (prints enabled/disabled)
• Mask unit preventing it from starting:
◦ `systemctl mask `
• Unmask unit:
◦ `systemctl unmask `
• Reload systemd (rescan for new/changed units):
◦ `systemctl daemon-reload`
# Working with targets:
• Set default target (similar to SysV runlevels):
◦ `systemctl set-default `
◦ e.g. `systemctl set-default graphical`
◦ might require ‘-f’ to override previous default
• Change current target (equivalent to telinit ):
◦ `systemctl isolate `
# Working with cgroups:
• Show control group contents recursively
◦ `systemd-cgls`
# Troubleshooting:
• Listing failed units:
◦ `systemctl --failed`
• Finding info about failed/problem units:
◦ `journalctl _PID=` # Unit PID can be found using → `systemctl status `
◦ see Journaling below for more tips.
# Journaling:
• To simply invoke the journal:
◦ `journalctl`
• Show boot messages:
◦ current boot:
◦ `journalctl -b`
◦ specific boot:
◦ `journalctl -b ` # Where ‘’ can be 0 for current or -n for previous nth boot
◦ list all boots:
◦ `journalctl --list-boots`
• List all messages from unit
◦ `journalctl -u `
• Show kernel ring buffer (`dmesg`)
◦ `journalctl -k`
• Show messages related to specific executable:
◦ `journalctl /path/to/executable`
• Follow most recent entries (and forthcoming entries)
◦ `journalctl -f`
◦ can be combined with -u to follow a unit and new entries
◦ `journalctl -f -u `