Use systemd in Linux like a Pro – A cheat sheet
As systemd becomes the default method of handling services in all major Linux distributions, below are some quick and easy-to-remember commands that will make you look like a pro.
systemctl
- check for all running units
systemctl
TIP: To show all units, including in-active ones:
systemctl list-unit-files
- Check for failed units
systemctl --failed
- Start, stop, restart units
systemctl start postfix.service
systemctl restart postfix.service
systemctl stop postfix.service
- Check status of a specific unit
systemctl status mysqld.service
TIP: Use -l for detailed status
- Enable or disable services
systemctl enable firewalld.service
systemctl disable NetworkManager.service
TIP: If you disable a service, and it still runs,
systemctl mask NetworkManager.service
Use ‘unmask’ to restore it
- See if a specific unit is enabled
systemctl is-enabled iptables.service
- Create a snapshot – useful for testing various targets
systemctl snapshot example.snapshot
TIP: To activate it:
systemctl isolate example.snapshot
- Reboot/poweroff/suspend your machine
systemctl reboot
systemctl poweroff
systemctl suspend
- Change current target – i.e. runlevel
systemctl isolate graphical.target
- To list current target
systemctl list-units --type=target
systemd
- See which units take a long time to start during boot up
systemd-analyze blame
TIP: You can plot the boot up using:
systemd-analyze plot
- See when a unit started and how long it took
systemd-analyze critical-chain
journalctl
- Create a running log like ‘tail -f /var/log/messages’
journalctl -f -o cat --no-pager
- Running log for a specific unit
journalctl -f -o cat --no-pager -u httpd.service
- See boot messages – like ‘dmesg’
journalctl -b
Manage remote systems:
systemctl status sshd -H root@1.2.3.4
For detailed instructions on these and more commands, man as always is your best friend.