Thursday, September 4, 2014

Systemd Cheat Sheet

I'm still getting used to systemd commands and syntax. Here are some common tasks and their commands. (**This is a living doc and content will be added as needed)

-----
Show duration of the last boot:
$ systemd-analyze

Show how long each systemd unit took to start on last boot:
$ systemd-analyze blame

Show the systemd journal:
$ journalctl

Show all systemd journal events for today:
$ journalctl --since=today

Show all errors in the systemd journal:
$ journalctl -p err

Show the default run level:
$ systemctl get-default

Set default run level:
$ ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/default.target

Set default run level to multi-user (run level 3):
$ ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

Set default run level to graphical (run level 5):
$ ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

Change to a different run level:
$ systemctl isolate <target name>.target

List active "units", as they are called (i.e. services, targets, mounts, etc):
$ systemctl

List units that are services:
$ systemctl -t service

List the status of a specific unit:
$ systemctl status <unit>
Example:
$ systemctl status sshd.service

Check if a service is enabled:
$ systemctl is-enabled <service>
Example:
$ systemctl is-enabled sshd.service
$ enabled

Kill all the processes of a given service:
$ systemctl kill <name>.service
Example:
$ systemctl kill crond.service

List all units and their state:
$ systemctl list-unit-files

Reload systemd, scanning for new or changed units:
$ systemctl daemon-reload

Display process details plus control group info. This is a great command to make an alias for.

$ ps xawf -eo pid,user,cgroup,args

Set the hostname:
$ hostnamectl set-hostname <name>

No comments:

Post a Comment