In RHEL7 or CentOS7, For managing service one new method is introduced systemct. To view, start, stop, restart, enable, or disable system services, use the systemctl command.

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.

#systemctl restart httpd.service
#systemctl restart httpd

let see some examples and comparison for same.

Displaying Service Status

How to display service status.

#systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2016-02-03 14:07:01 IST; 7h ago
  Process: 9340 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 9341 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─9341 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Feb 03 14:07:01 srv7 systemd[1]: Starting Vsftpd ftp daemon...
Feb 03 14:07:01 srv7 systemd[1]: Started Vsftpd ftp daemon.

In above outputs there are some fields which were dscriped as below

Field Description
Loaded Information whether the service unit has been loaded, the absolute path to the unit file, and a note whether the unit is enabled.
Active Information whether the service unit is running followed by a time stamp.
Main PID The PID of the corresponding system service followed by its name.
Status Additional information about the corresponding system service.
Process Additional information about related processes.
CGroup Additional information about related Control Groups (cgroups).

It is possible to know only statue of service on system.

#systemctl is-active vsftpd
active

It is possible to know service is enable on boot or not

#systemctl is-enabled mariadb
disabled
#systemctl is-enabled vsftpd
enabled

Listing Services

TO List all installed services. Use Below commands.

Installed and Active services

#systemctl list-units --type service
  UNIT                                                           LOAD   ACTIVE SUB     DESCRIPTION
  auditd.service                                                 loaded active running Security Auditing Service
  avahi-daemon.service                                           loaded active running Avahi mDNS/DNS-SD Stack
  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
    
     .....

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.

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

Above command show for every service output have Load, Active, Sub and description

Above command only display active units. We can list all installed or loaded service or units.

#systemctl list-units --type service --all
  UNIT                                        LOAD      ACTIVE   SUB     DESCRIPTION
  auditd.service                              loaded    active   running Security Auditing Service
  avahi-daemon.service                        loaded    active   running Avahi mDNS/DNS-SD Stack
  brandbot.service                            loaded    inactive dead    Flexible Branding Service
  cpupower.service                            loaded    inactive dead    Configure CPU power related settings
  crond.service                               loaded    active   running Command Scheduler
  dbus.service                                loaded    active   running D-Bus System Message Bus
      .....

You can list all services enabled or disabled or any state

#systemctl list-unit-files --type service

you can list all services in only enabled state

#systemctl list-unit-files --type service --state enabled
UNIT FILE                                   STATE
auditd.service                              enabled
avahi-daemon.service                        enabled
crond.service                               enabled
dbus-org.fedoraproject.FirewallD1.service   enabled
dbus-org.freedesktop.Avahi.service          enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service  enabled

Same you can check various service states.

systemctl list-unit-files --type service --state disabled
systemctl list-unit-files --type service --state invalid
systemctl list-unit-files --type service --state static

Sometime we like to know order of service start at boot time after or before specfic service.

vsftpd.service
● ├─system.slice
● ├─systemd-journald.socket
● ├─basic.target
● │ ├─rhel-import-state.service
● │ ├─systemd-ask-password-plymouth.path
● │ ├─paths.target
● │ │ ├─brandbot.path
● │ │ ├─systemd-ask-password-console.path
● │ │ └─systemd-ask-password-wall.path
● │ ├─slices.target
● │ │ ├─-.slice
● │ │ ├─system.slice
● │ │ └─user.slice
#systemctl list-dependencies --before vsftpd
vsftpd.service
● ├─multi-user.target
● │ ├─systemd-readahead-done.service
● │ ├─systemd-readahead-done.timer
● │ ├─systemd-update-utmp-runlevel.service
● │ └─graphical.target
● │   └─systemd-update-utmp-runlevel.service
● └─shutdown.target
●   ├─systemd-reboot.service
●   └─final.target
●     └─systemd-reboot.service

Start , Stop and restart of Service

For start ,stop, restart and reload of service use below commands.

#systemctl stop vsftpd
#systemctl start vsftpd
#systemctl restart vsftpd
#systemctl reload vsftpd

Enabling or Disabling of service

To start service automatically on boot time, we have enable service. For reverse we have to disable service with below commands.

#systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
#systemctl is-enabled vsftpd
enabled
#systemctl disable vsftpd
Removed symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service.
#systemctl is-enabled vsftpd
disabled

Some of comparison in between service command and 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.

Some of comparison in between chkconfig command and systemctl

chkconfig systemctl Description

schkconfig 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.