Skip to content

Instantly share code, notes, and snippets.

@mofelee
Forked from mbodo/Linux - Systemd cheatsheet.md
Created February 21, 2017 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mofelee/efb91ba8433dcb82f46ac1e04338280d to your computer and use it in GitHub Desktop.
Save mofelee/efb91ba8433dcb82f46ac1e04338280d to your computer and use it in GitHub Desktop.
Systemd cheatsheet

Linux - Systemd cheatsheet

systemctl

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 $?

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

systemctl isolate multi-user.target

Change default.target:

Remove configured default target

rm /etc/systemd/system/default.target

Create default.target as symbolic link to multi-user.target

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.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:
```shell
# /run/systemd/generator.late/network.service
# Automatically generated by systemd-sysv-generator
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/network
Description=LSB: Bring up/down networking
Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target network-online.target network.target
After=iptables.service ip6tables.service NetworkManager-wait-online.service NetworkManager.service
Wants=network-online.target
Conflicts=shutdown.target
[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/rc.d/init.d/network start
ExecStop=/etc/rc.d/init.d/network stop
ExecReload=/etc/rc.d/init.d/network reload

Reference links:

Pid Eins:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment