User Tools

Site Tools


linux:systemd

systemd

Controlling systemd

The main command used to control systemd is systemctl. Some of its subcommands are as follows:

  • systemctl list-units - List all units (where unit is the term for a job/service)
  • systemctl start [NAME…] - Start (activate) one or more units
  • systemctl stop [NAME…] - Stop (deactivate) one or more units
  • systemctl enable [NAME…] - Enable one or more unit files
  • systemctl disable [NAME…] - Disable one or more unit files
  • systemctl reboot - Shut down and reboot the system

Examples:

  • How do you see only available services, running or not?
# systemctl list-units -t service --all
  • How do you see only active services?
# systemctl list-units -t service
  • How to see status of OpenSSH service?
# systemctl status sshd.service
or shorter:
# systemctl status sshd
  • How to stop, start or restart service?
# systemctl <stop|start|restart> sshd
  • How to make service to start at boot?
# systemctl enable sshd
  • How to disable it from starting at boot?
# systemctl disable sshd

Journal

  • Show all messages from this boot:
# journalctl -b

However, often one is interested in messages not from the current, but from the previous boot (e.g. if an unrecoverable system crash happened). This is possible through optional offset parameter of the -b flag: journalctl -b -0 shows messages from the current boot, journalctl -b -1 from the previous boot, journalctl -b -2 from the second previous and so on. See man 1 journalctl for full description, the semantics is much more powerful.

  • Show all messages from date (and optional time):
# journalctl --since="2012-10-30 18:17:16"
  • Show all messages since 20 minutes ago:
# journalctl --since "20 min ago"
  • Follow new messages:
# journalctl -f
  • Show all messages by a specific executable:
# journalctl /usr/lib/systemd/systemd
  • Show all messages by a specific process:
# journalctl _PID=1
  • Show all messages by a specific unit:
# journalctl -u netcfg
  • Show kernel ring buffer:
# journalctl -k
  • Show only error, critical, and alert priority messages
# journalctl -p err..alert

Numbers also can be used, journalctl -p 3..1. If single number/keyword used, journalctl -p 3 - all higher priority levels also included.

  • Show auth.log equivalent by filtering on syslog facility:
# journalctl SYSLOG_FACILITY=10

systemd for Administrators

The above systemd in four parts comes from PID EINS! blog. I have mirrored it in case it gets lost somewhere. Please credit PID EINS! for his great work.

linux/systemd.txt · Last modified: 2017/04/06 01:56 by abadonna