The Systemd system management daemon was designed to replace current init system inherited from UNIX System V operating systems such Linux and thus making current init system obsolete. It this tutorial we will discuss some systemd basics such as how to start or stop service and see service status using systemctl
command.
Let’s start with little bit of information about our systemd version. Use the below systemctl
command to determine systemd version:
[root@rhel7 ~]# systemctl --version systemd 208 +PAM +LIBWRAP +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ
Next, we use systemctl
command to list all currenly running services on our Redhat Linux server system:
[root@rhel7 ~]# systemctl list-units --type=service | grep running
Similarly we can list all services which failed to load during the system’s boot time:
[root@rhel7 ~]# systemctl list-units --type=service | grep failed fprintd.service loaded failed failed Fingerprint Authentication Daemon rhnsd.service loaded failed failed LSB: Starts the Spacewalk Daemon rngd.service loaded failed failed Hardware RNG Entropy Gatherer Daemon
If you are interested in all active services available on your system simply execute the above systemctl
command without the grep pipe:
[root@rhel7 ~]# systemctl list-units --type=service ... ... ... systemd-udevd.service loaded active running udev Kernel Device Manager systemd-update-utmp.service loaded active exited Update UTMP about System Reboot/Shutdown systemd-user-sessions.service loaded active exited Permit User Sessions systemd-vconsole-setup.service loaded active exited Setup Virtual Console tuned.service loaded active running Dynamic System Tuning Daemon upower.service loaded active running Daemon for power management vboxadd-service.service loaded active running LSB: VirtualBox Additions service vboxadd-x11.service loaded active exited LSB: VirtualBox Linux Additions kernel modules vboxadd.service loaded active exited LSB: VirtualBox Linux Additions kernel modules 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. 68 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
The above command will only list active services. To list all services including inactive services run:
[root@rhel7 ~]# systemctl list-units --type=service --all
Once we have located the service we whish to start, stop, restart or get a status on, we use systemctl
command with a following syntax:
systemctl COMMAND SERVICE
So for example to stop our Postfix Mail Transport Agent:
postfix.service loaded active running Postfix Mail Transport Agent
We can issue a systemctl
command:
[root@rhel7 ~]# systemctl stop postfix.service OR SIMPLY [root@rhel7 ~]# systemctl stop postfix
Later we can check the status using:
[root@rhel7 ~]# systemctl status postfix.service postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled) Active: inactive (dead) since Mon 2014-09-15 12:27:09 WST; 5s ago
Depending on the service you are trying to manage you can use various different commands such as stop, start, restart, status, reload, kill etc. Check the manual page of systemctl
command to get a full list of commands.