April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

CentOS / RHEL 7 : Beginners guide to systemd service units

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

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

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>