SystemCTL Cheat Sheet (BASH)

Whether or not you like SystemD it is a reality of the world we currently live in, and anyone managing a modern operating system is likely to have a need to interact with it.

Utilities such as service,ckconfig and update.rc-d have largely been replaced with systemctl and it's syntax isn't always as simple and intuitive - especially when you're used to the other ways of doing things

Similar To

  • chkconfig
  • service
  • update-rc.d

Details

  • Language: BASH

Snippet

## Interacting with services

# Start service foo
# equiv: service foo start
systemctl start foo

# Stop service foo
# equiv: service foo stop
systemctl stop foo

# Restart service foo
# equiv: service foo restart
systemctl restart foo

# Reload service foo
# equiv: service foo reload
systemctl reload foo

# Conditional restart service foo
# equiv: service foo condrestart
systemctl condrestart foo

# Get status of service foo
# equiv: service foo status
systemctl status foo

## Managing services

# Disable service foo
# equiv: chkconfig foo off
systemctl disable foo.service

# Enable service foo
# equiv: chkconfig foo on
systemctl enable foo.service

# Check whether foo is enabled
# equiv: chkconfig foo
systemctl is-enabled foo.service

# Check what levels foo runs at
# equiv: chkconfig foo --list
ls /etc/systemd/system/*.wants/foo.service

## Checking runlevels and services

# List service unit files (what would have been init scripts)
# equiv: chkconfig --list
systemctl list-unit-files --type=service

# List services that run at runlevel 5 (graphical mode)
# equiv: chkconfig --list | grep 5:on
systemctl list-dependancies graphical.target

## General

# Force systemd to rescan unit files after you've made changes
# No equiv
systemctl daemon-reload

# Change to runlevel 3
# equiv: telinit 3
systemctl isolate runlevel3.target

# Make runlevel 3 the default runlevel
ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target

# Specifying runlevel from Grub
#
# Edit the kernel command line in grub like you would to add init=/bin/bash
# but add
systemd.unit=runlevel3.target #or
system.unit=resuce.target