Advantages of Systemd vs. SysVinit, with Example Commands

NOTE: This article applies to more recent Linux distrubutions:

  • RHEL/CentOS 7+
  • Fedora 21+
  • Debian 8+
  • Ubuntu 16+

The experienced System Administrator will know SysVinit and the perennial init commands used to control system run levels, for example, init 6 to reboot.

As of 2014, however, most Linux distributions now rely on the newer Systemd system and service manager. While the init commands can still be used there are some notable advantages that Systemd offers. Below are a few such advantages.

  • Systemd daemons make it is easier to supervise and control processes and parallelized job execution.
  • Systemd offers the systemctl command and cgroups to make your life easier:
    • systemctl provides the administrator with more detailed error messages including runtime and start-up errors.
    • cgroups, or "control groups", allow for the grouping of processes into a hierarchy for easier management.
  • Process attributes such as function and ownership are much easier to ascertain. For example, under Systemd, sub-processes, once spawned, become 'children' and are organized under the appropriate 'parent' group to show inheritance.

To see an example of the clear visual hierarchy and process management under Systemd, try the pstree command.

On my CentOS 7 system it looks like this:

pstree

Useful Systemd Commands:

For controlling runlevels:

  1. systemctl poweroff --> shut down (enter runlevel 0)
  2. systemctl rescue.target --> enter rescue mode (runlevel 1, single-user)
  3. systemctl multi-user.target --> enter multi-user mode (runlevels 2 through 4)
  4. systemctl graphical.target --> enter graphical mode (runlevel 5)
  5. systemctl reboot --> reboot the system (runlevel 6)

For controlling services:

  1. systemctl start dummy.service --> start the "dummy" service
  2. systemctl stop dummy.service --> stop the "dummy" service
  3. systemctl restart dummy.service --> restart the "dummy" service
  4. systemctl status dummy.service --> get status of "dummy" service
  5. systemctl kill dummy --> kill all processes related to "dummy" service

Miscellaneous:

  1. journalctl -f --> follow the system logs (i.e. tail -f /var/log/messages)
  2. journalctl --since=today --> get logs of all events that have occurred today
  3. hostnamectl --> get system hostname and other host information
  4. timedatectl --> get system date, time, and timezone information

SOURCE: Linoxide's write-up here: https://linoxide.com/linux-command/systemd-vs-sysvinit-cheatsheet (includes beautiful, downloadable PDF version)