Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Systemd cheatsheet

Linux - Systemd cheatsheet


Activates a service immediately:

systemctl start foo.service

Deactivates a service immediately:

systemctl stop foo.service

Restarts a service:

systemctl restart foo.service

Shows status of a service including whether it is running or not:

systemctl status foo.service

Enables a service to be started on bootup:

systemctl enable foo.service

Disables a service to not start during bootup:

systemctl disable foo.service

Check whether a service is already enabled or not:

0 indicates that it is enabled. 1 indicates that it is disabled

systemctl is-enabled foo.service; echo $?

Change ad-hoc runlevel with systemctl isolate command:

Switch to another target (in this case multi-user/runlevel 3 in old SysV):

systemctl isolate

Switch to graphical target (in this case graphical/runlevel 5 in old SysV):

systemctl isolate

Change permanently change

Remove configured default target

rm /etc/systemd/system/

Create as symbolic link to

ln -sf /lib/systemd/system/ /etc/systemd/system/

Set default target through systemctl

To find a [new target]:

- To get active targets, 
  systemctl --type=target list-units
- To get all targets, (active/inactive)
  systemctl --type=target --all list-units
- To list available targets, (ls -l /usr/lib/systemd/system/*.target)
  systemctl --type=target list-unit-files

systemctl set-default [new target]

List-units by pattern:

systemctl list-units *etwok*.service

Example content:
UNIT                   LOAD   ACTIVE SUB     DESCRIPTION
network.service        loaded active exited  LSB: Bring up/down networking
NetworkManager.service loaded active running Network Manager

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed. Pass --all to see loaded but inactive units, too.

Display a content of unit file

systemctl cat network.service

Displayed content:

# /run/systemd/generator.late/network.service
# Automatically generated by systemd-sysv-generator
Description=LSB: Bring up/down networking
After=iptables.service ip6tables.service NetworkManager-wait-online.service NetworkManager.service
ExecStart=/etc/rc.d/init.d/network start
ExecStop=/etc/rc.d/init.d/network stop
ExecReload=/etc/rc.d/init.d/network reload

Suppress non zero exit code (service after stop will be displayed as inactive, not failed):



How to put PID of service as variable to service systemd file:

ExecReload=/bin/kill -s HUP $MAINPID


List all services with pattern

<pattern> - httpd e.g

systemctl list-units -t service --full| cut -d' ' -f1 | grep <pattern> | while read s; do systemctl status $s; done


Reference links:

Pid Eins:

Digital Ocean:


This comment has been minimized.

Copy link

commented Mar 2, 2018

It's easier to use systemctl set-default [new target] to setup


This comment has been minimized.

Copy link
Owner Author

commented Apr 14, 2018

Avin thank you. It goes straight to the cheatsheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.