Working with Services in RHEL/Centos 7

### It’s possible to check all services like follow:

# the list of all services

[root@testos]# systemctl list-unit-files -t service
UNIT FILE                                     STATE
abrt-ccpp.service                             enabled
abrt-oops.service                             enabled
abrt-pstoreoops.service                       disabled
abrt-vmcore.service                           enabled
abrt-xorg.service                             enabled
abrtd.service                                 enabled
arp-ethers.service                            disabled
atd.service                                   enabled
auditd.service                                disabled
auth-rpcgss-module.service                    static
autofs.service                                disabled
autovt@.service                               enabled
blk-availability.service                      disabled
brandbot.service                              static
certmonger.service                            enabled
chrony-dnssrv@.service                        static
chrony-wait.service                           disabled
chronyd.service                               disabled
console-getty.service                         disabled
console-shell.service                         disabled
container-getty@.service                      static
containerd.service                            disabled
cpupower.service                              disabled
crond.service                                 enabled
dbus-org.freedesktop.hostname1.service        static
dbus-org.freedesktop.import1.service          static
dbus-org.freedesktop.locale1.service          static
dbus-org.freedesktop.login1.service           static
dbus-org.freedesktop.machine1.service         static
dbus-org.freedesktop.timedate1.service        static
dbus.service                                  static
debug-shell.service                           disabled
dirsrv@.service                               enabled
.
.

# display the list of services which are running

[root@testos]# systemctl -t 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
  certmonger.service                 loaded active running Certificate monitoring and PKI enrollment
  containerd.service                 loaded active running containerd container runtime
  crond.service                      loaded active running Command Scheduler
  dbus.service                       loaded active running D-Bus System Message Bus
  dirsrv@MTNIRANCELL-IR.service      loaded active running 389 Directory Server MTNIRANCELL-IR.
  docker.service                     loaded active running Docker Application Container Engine
  getty@tty1.service                 loaded active running Getty on tty1
  gssproxy.service                   loaded active running GSSAPI Proxy Daemon
  httpd.service                      loaded active running The Apache HTTP Server
  ipa-custodia.service               loaded active running IPA Custodia Service
  ipa.service                        loaded active exited  Identity, Policy, Audit
  irqbalance.service                 loaded active running irqbalance daemon
  kadmin.service                     loaded active running Kerberos 5 Password-changing and Administration
  kmod-static-nodes.service          loaded active exited  Create list of required static device nodes for the current kernel
  krb5kdc.service                    loaded active running Kerberos 5 KDC
  libstoragemgmt.service             loaded active running libstoragemgmt plug-in server 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 progress polling
  lvm2-pvscan@8:16.service           loaded active exited  LVM2 PV scan on device 8:16
  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
  ntpd.service                       loaded active running Network Time Service
  oddjobd.service                    loaded active running privileged operations for unprivileged applications
  pki-tomcatd@pki-tomcat.service     loaded active running PKI Tomcat Server pki-tomcat
  polkit.service                     loaded active running Authorization Manager
  postfix.service                    loaded active running Postfix Mail Transport Agent
.
.
### Start/Stop/status/restart/enable/disable a service:
[root@testos]#  systemctl stop httpd

[root@testos]#  systemctl start httpd

[root@testos]#  systemctl restart httpd

[root@testos]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/httpd.service.d
           └─ipa.conf
   Active: active (running) since Wed 2022-11-30 15:47:20 +0330; 6s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 1603 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 1615 ExecStartPre=/usr/libexec/ipa/ipa-httpd-kdcproxy (code=exited, status=0/SUCCESS)
 Main PID: 1620 (httpd)
   Status: "Processing requests..."
    Tasks: 60
   Memory: 430.9M
   CGroup: /system.slice/httpd.service
           ├─1620 /usr/sbin/httpd -DFOREGROUND
           ├─1622 /usr/libexec/nss_pcache 98364 off
           ├─1625 (wsgi:kdcproxy) -DFOREGROUND
           ├─1626 (wsgi:kdcproxy) -DFOREGROUND
           ├─1627 (wsgi:ipa)      -DFOREGROUND
           ├─1628 (wsgi:ipa)      -DFOREGROUND
           ├─1629 (wsgi:ipa)      -DFOREGROUND
           ├─1630 (wsgi:ipa)      -DFOREGROUND
           ├─1631 /usr/sbin/httpd -DFOREGROUND
           ├─1632 /usr/sbin/httpd -DFOREGROUND
           ├─1633 /usr/sbin/httpd -DFOREGROUND
           ├─1634 /usr/sbin/httpd -DFOREGROUND
           └─1635 /usr/sbin/httpd -DFOREGROUND

Nov 30 15:47:19 rhel7-67130 systemd[1]: Starting The Apache HTTP Server...
Nov 30 15:47:20 rhel7-67130 ipa-httpd-kdcproxy[1615]: ipa: INFO: KDC proxy enabled
Nov 30 15:47:20 rhel7-67130 ipa-httpd-kdcproxy[1615]: ipa-httpd-kdcproxy: INFO     KDC proxy enabled
Nov 30 15:47:20 rhel7-67130 systemd[1]: Started The Apache HTTP Server.

[root@testos]# systemctl disable httpd
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.

[root@testos]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

### There are some SysV services yet. Those are controlled by chkconfig like below:
[root@testos]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rhnsd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

Leave a Comment