• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 7 : Beginners guide to systemd service units

by admin

Previous versions of Oracle Linux use init scripts located in the /etc/rc.d/init directory to start and stop services. In RHEL 7, these init scripts have been replaced with systemd service units. Service units have a .service extension. Use the systemctl command to list all loaded service 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
.....

Here,
LOAD – service load state
high-level (ACTIVE) and low-level (SUB) unit activation state
DESCRIPTION – description of the service unit.

Omit the –all option to list only the active service units. Use the list-unit-files option to see which service units are enabled:

# systemctl list-unit-files --type service

systemd service units status

Displaying status of the services

systemd service units correspond to system services. Use the following command to display detailed information about a service unit. This example displays information about the sshd service unit.

# systemctl status sshd

systemd status sshd

The following information is available for the specified service unit:

Loaded: If the service is loaded, the absolute path to the service unit file, and if the
service unit is enabled
Active: If the service unit is running and a timestamp
Main PID: The Process ID of the corresponding system service and the service name
Status: Additional information about the corresponding system service
Process: Additional information about related processes
CGroup: Additional information about related Control Groups

To check whether a service is running (active) or not running (inactive):

# systemctl is-active sshd
active

To check whether a service is enabled:

# systemctl is-enabled sshd
enabled

Starting and Stopping Services

In previous versions of RHEL, the service utility is used to stop and start services. In RHEL 7, the systemctl utility provides an equivalent set of subcommands. The table below shows a comparison of the service utility with systemctl.

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

Enabling and disabling services

In previous versions of RHEL, the chkconfig utility is used to enable and disable services. In RHEL 7, the systemctl utility provides an equivalent set of subcommands. The table below shows a comparison of the chkconfig utility with systemctl.

chkconfig Utility systemctl Utility Description
chkconfig name on systemctl enable name Enables a service
chkconfig name off systemctl disable name Disables a service
chkconfig –list name systemctl status name, systemctl is-enabled name Checks whether a service is enabled
chkconfig –list systemctl list-unit-files –type service Lists all services and checks whether they are enabled

Filed Under: CentOS/RHEL 7

Some more articles you might also be interested in …

  1. How to backup Linux OS using “dd” Command
  2. How to Enable X11 Forwarding on CentOS/RHEL 5,6,7
  3. CentOS/RHEL: How to find the package with a missing file using YUM
  4. Understanding SELinux Booleans
  5. How to Switch Back To Previous Version of openjdk in CentOS/RHEL
  6. MySQL Fails to Start Using systemctl On systemd Linux Distributions
  7. How to Make User Account Read-Only in CentOS/RHEL 7
  8. “polkit code=exited status=1/FAILURE” – PolicyKit Failing to Start in CentOS/RHEL 7 and 8
  9. Rsyslog : How to Send log files to remote server in CentOS/RHEL 6,7
  10. passwd: gkr-pam: couldn’t update the login keyring password: no old password was entered

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright