Lesson 101: systemctl Command
In this lesson, you'll learn how to use the systemctl command to control and manage system services, mount points, sockets, and runlevels in Linux.
A squaresystemctl is a systemd utility that is responsible for controlling the systemd system and service manager.
Systemd is a collection of system management daemons, utilities, and libraries that serve as a replacement for the System V init daemon.
Systemd functions as a central management and configuration platform for UNIX-like systems.
In Linux, the ecosystem systemd has been implemented on most of the standard Linux distributions, with a few exceptions.
Systemd is the parent process of all other daemons, often but not always.
Let's discuss how to control the system and services on a system running systemd.
systemctl Command Syntax
$ systemctl [COMMAND] [UNIT]
systemctl Command Options
| Command | Description |
|---|---|
--version |
Display the installed systemd version |
list-unit-files |
List all available unit files |
list-units |
List all currently running units |
--failed |
List all failed units |
is-enabled UNIT |
Check if a unit is enabled |
status UNIT |
Show the current status of a unit |
start UNIT |
Start a unit |
stop UNIT |
Stop a unit |
restart UNIT |
Restart a unit |
reload UNIT |
Reload a unit's configuration |
enable UNIT |
Enable a unit to start at boot |
disable UNIT |
Disable a unit from starting at boot |
is-active UNIT |
Check if a unit is currently active |
mask UNIT |
Prevent a unit from starting |
unmask UNIT |
Remove the mask from a unit |
kill UNIT |
Kill all processes of a unit |
show UNIT |
Show all configuration of a unit |
list-dependencies UNIT |
List dependencies of a unit |
set-property UNIT PROP=VAL |
Set a runtime property of a unit |
get-default |
Show the current default runlevel target |
set-default TARGET |
Set the default runlevel target |
isolate TARGET |
Switch to a specific runlevel target |
rescue |
Enter rescue/maintenance mode |
emergency |
Enter emergency mode |
reboot |
Reboot the system |
halt |
Halt the system |
suspend |
Suspend the system |
hibernate |
Hibernate the system |
hybrid-sleep |
Put the system in hybrid sleep |
.service), mount points (.mount), sockets (.socket) and devices (.device) as units.Systemd and Systemctl Basics
1. Check the Installed systemd Version
First, check if systemd is installed on your system or not, and what version of the currently installed systemd is?
$ systemctl --version
systemd 249 (249.11-0ubuntu3.9)
+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified
It's clear from the above example that we have systemd version 249 installed.
2. Check the Location of systemd Binaries and Libraries
Check where the binaries and libraries of systemd and systemctl are installed.
$ whereis systemd
systemd: /usr/bin/systemd /usr/lib/systemd /etc/systemd /usr/share/systemd /usr/share/man/man1/systemd.1.gz
$ whereis systemctl
systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz