Managing System Services

Previous versions of Red Hat Enterprise Linux, which were distributed with SysV init or Upstart, used init scripts located in the /etc/rc.d/init.d/ directory. These init scripts were typically written in Bash, and allowed the system administrator to control the state of services and daemons in their system. In Red Hat Enterprise Linux 7, these init scripts have been replaced with service units.

Highlights of systemd:

  • It supports the Parallelization  which increases the system boot time.
  • Systemd creates the sockets for each daemons  and it just needs to connect to the sockets.
  • Automatic service dependency management which can prevent long time-outs.
  • A method of tacking related processes together by using Linux control groups.
  • Still RHEL 7 supports the shell scripts  for  few legacy services.(/etc/init.d).

Comparison of the service Utility with systemctl

service systemctl Description
service name start
systemctl start name.service
Starts a service.
service name stop
systemctl stop name.service
Stops a service.
service name restart
systemctl restart name.service
Restarts a service.
service name condrestart
systemctl try-restart name.service
Restarts a service only if it is running.
service name reload
systemctl reload name.service
Reloads configuration.
service name status
systemctl status name.service
systemctl is-active name.service
Checks if a service is running.
service --status-all
systemctl list-units --type service --all
Displays the status of all services.

 

Table 9.4. Comparison of the chkconfig Utility with systemctl

chkconfig systemctl Description
chkconfig name on
systemctl enable name.service
Enables a service.
chkconfig name off
systemctl disable name.service
Disables a service.
chkconfig --list name
systemctl status name.service
systemctl is-enabled name.service
Checks if a service is enabled.
chkconfig --list
systemctl list-unit-files --type service
Lists all services and checks if they are enabled.
chkconfig --list
systemctl list-dependencies --after
Lists services that are ordered to start before the specified unit.
chkconfig --list
systemctl list-dependencies --before
Lists services that are ordered to start after the specified unit.

The systemctl  is a  command to manage the different type of objects. These objects are called “units” .

[root@hanskarri-rhel rpm-gpg]# systemctl -t help
Available unit types:
service
socket
busname
target
snapshot
device
mount
automount
swap
timer
path
slice
scope
[root@hanskarri-rhel rpm-gpg]#

To list all the available services on the system, use the below command.

[root@hanskarri-rhel rpm-gpg]# systemctl --type=service
 UNIT LOAD ACTIVE SUB DESCRIPTION
 abrt-ccpp.service loaded active exited Install ABRT coredump hook
 abrt-oops.service loaded active running ABRT kernel log watcher
 abrtd.service loaded active running ABRT Automated Bug Reporting Tool
 atd.service loaded active running Job spooling tools
 auditd.service loaded active running Security Auditing Service
 chronyd.service loaded active running NTP client/server
 crond.service loaded active running Command Scheduler
 dbus.service loaded active running D-Bus System Message Bus
 firewalld.service loaded active running firewalld - dynamic firewall daemon
 getty@tty1.service loaded active running Getty on tty1
 gssproxy.service loaded active running GSSAPI Proxy Daemon
 iscsi-shutdown.service loaded active exited Logout off all iSCSI sessions on shutdown
 kdump.service loaded active exited Crash recovery kernel arming
 kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current ke
 ksm.service loaded active exited Kernel Samepage Merging
 ksmtuned.service loaded active running Kernel Samepage Merging (KSM) Tuning Daemon
 libstoragemgmt.service loaded active running libstoragemgmt plug-in server daemon
 libvirtd.service loaded active running Virtualization daemon
 lvm2-lvmetad.service loaded active running LVM2 metadata daemon
 lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or p
 lvm2-pvscan@8:2.service loaded active exited LVM2 PV scan on device 8:2
 network.service loaded active exited LSB: Bring up/down networking
 NetworkManager.service loaded active running Network Manager
 nfs-config.service loaded active exited Preprocess NFS configuration
 polkit.service loaded active running Authorization Manager
 postfix.service loaded active running Postfix Mail Transport Agent
 rhel-dmesg.service loaded active exited Dump dmesg to /var/log/dmesg
 rhel-import-state.service loaded active exited Import network configuration from initramfs
 rhel-readonly.service loaded active exited Configure read-only root support
 rhnsd.service loaded active running LSB: Starts the Spacewalk Daemon
 rhsmcertd.service loaded active running Enable periodic update of entitlement certificates.
● rngd.service loaded failed failed Hardware RNG Entropy Gatherer Daemon
 rsyslog.service loaded active running System Logging Service
 smartd.service loaded active running Self Monitoring and Reporting Technology (SMART) Daemon
 sshd.service loaded active running OpenSSH server daemon
 sysstat.service loaded active exited Resets System Activity Logs
 systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
 systemd-journald.service loaded active running Journal Service
 systemd-logind.service loaded active running Login Service
 systemd-random-seed.service loaded active exited Load/Save Random Seed
 systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
 systemd-sysctl.service loaded active exited Apply Kernel Variables
 systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
 systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
 systemd-udev-settle.service loaded active exited udev Wait for Complete Device Initialization
 systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
 systemd-udevd.service loaded active running udev Kernel Device Manager
 systemd-update-utmp.service loaded active exited Update UTMP about System Boot/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
 wpa_supplicant.service loaded active running WPA Supplicant daemon

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.

52 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
~

To check the specific service status ,

[root@hanskarri-rhel rpm-gpg]# systemctl status upower.service
● upower.service
 Loaded: not-found (Reason: No such file or directory)
 Active: inactive (dead)
[root@hanskarri-rhel rpm-gpg]# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
 Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
 Active: active (running) since Fri 2017-04-14 23:09:08 IST; 1h 22min ago
 Docs: man:sshd(8)
 man:sshd_config(5)
 Main PID: 1265 (sshd)
 CGroup: /system.slice/sshd.service
 └─1265 /usr/sbin/sshd -D
Apr 14 23:09:08 hanskarri-rhel systemd[1]: Started OpenSSH server daemon.
Apr 14 23:09:08 hanskarri-rhel systemd[1]: Starting OpenSSH server daemon...
Apr 14 23:09:09 hanskarri-rhel sshd[1265]: Server listening on 0.0.0.0 port 22.
Apr 14 23:09:09 hanskarri-rhel sshd[1265]: Server listening on :: port 22.
Apr 14 23:09:29 hanskarri-rhel sshd[2550]: Accepted password for root from 192.168.58.1 port 50708 ssh2

Here Some Examples

[root@hanskarri-rhel rpm-gpg]# systemctl status sshd.service
● sshd.service - OpenSSH server daemon
 Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
 Active: active (running) since Fri 2017-04-14 23:09:08 IST; 4h 5min ago
 Docs: man:sshd(8)
 man:sshd_config(5)
 Main PID: 1265 (sshd)
 CGroup: /system.slice/sshd.service
 └─1265 /usr/sbin/sshd -D

Apr 14 23:09:08 hanskarri-rhel systemd[1]: Started OpenSSH server daemon.
Apr 14 23:09:08 hanskarri-rhel systemd[1]: Starting OpenSSH server daemon...
Apr 14 23:09:09 hanskarri-rhel sshd[1265]: Server listening on 0.0.0.0 port 22.
Apr 14 23:09:09 hanskarri-rhel sshd[1265]: Server listening on :: port 22.
Apr 14 23:09:29 hanskarri-rhel sshd[2550]: Accepted password for root from 192.168.58.1 port 50708 ssh2
[root@hanskarri-rhel rpm-gpg]#

To list the active and inactive  state of all loaded units, use the below command.

[root@hanskarri-rhel rpm-gpg]# systemctl list-units --type=service -all
 UNIT LOAD ACTIVE SUB DESCRIPTION
 abrt-ccpp.service loaded active exited Install ABRT coredump hook
 abrt-oops.service loaded active running ABRT kernel log watcher
 abrt-vmcore.service loaded inactive dead Harvest vmcores for ABRT
 abrt-xorg.service loaded inactive dead ABRT Xorg log watcher
 abrtd.service loaded active running ABRT Automated Bug Reporting Tool
● apparmor.service not-found inactive dead apparmor.service
 atd.service loaded active running Job spooling tools
 auditd.service loaded active running Security Auditing Service
 auth-rpcgss-module.service loaded inactive dead Kernel Module supporting RPCSEC_GSS
 brandbot.service loaded inactive dead Flexible Branding Service
 chronyd.service loaded active running NTP client/server
 cpupower.service loaded inactive dead Configure CPU power related settings
● crond.service masked inactive dead crond.service
 dbus.service loaded active running D-Bus System Message Bus
● display-manager.service not-found inactive dead display-manager.service

You can filter the failed services using the systemctl command with below mentioned options.

[root@hanskarri-rhel rpm-gpg]# systemctl --failed --type=service
 UNIT LOAD ACTIVE SUB DESCRIPTION
● rngd.service loaded failed failed Hardware RNG Entropy Gatherer Daemon

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.

1 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@hanskarri-rhel rpm-gpg]#

Specific service can be restarted using “systemctl restart” command.

[root@hanskarri-rhel rpm-gpg]# systemctl restart sshd
[root@hanskarri-rhel rpm-gpg]#


[root@hanskarri-rhel rpm-gpg]# systemctl status sshd
● sshd.service - OpenSSH server daemon
 Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
 Active: active (running) since Fri 2017-04-14 23:09:08 IST; 4h 11min ago
 Docs: man:sshd(8)
 man:sshd_config(5)
 Main PID: 1265 (sshd)
 CGroup: /system.slice/sshd.service
 └─1265 /usr/sbin/sshd -D

Apr 14 23:09:08 hanskarri-rhel systemd[1]: Started OpenSSH server daemon.
Apr 14 23:09:08 hanskarri-rhel systemd[1]: Starting OpenSSH server daemon...
Apr 14 23:09:09 hanskarri-rhel sshd[1265]: Server listening on 0.0.0.0 port 22.
Apr 14 23:09:09 hanskarri-rhel sshd[1265]: Server listening on :: port 22.
Apr 14 23:09:29 hanskarri-rhel sshd[2550]: Accepted password for root from 192.168.58.1 port 50708 ssh2
[root@hanskarri-rhel rpm-gpg]#