Skip to main content
RH124

Control and monitor network services and system daemons using systemd

By July 10, 2014September 12th, 2022No Comments

systemdWith the release of Red Hat Enterprise Linux 7 and CentOS 7 the Red Hat certification tracks also switch to version 7 and systemd. The new service manager to replay SysV Scripts is systemd which extends into managing much more than services. A whole ecosystem surrounds systemd allowing us to control the data and time, logging and hostname with systemd utilities. In this tutorial we take a look at managing services with systemd and the new tool systemctl that combines the functions of the service and chkconfig commands.

We will work through using the Apache Web server on CentOS 7. First of all we can check the status of the package by listing httpd packages:

# yum list httpd*

To install httpd service and documentation if they are not present, working as root we can issue the following commands:

# yum install -y httpd httpd-manual

Once installed the service unit, as they are known,  for the httpd server is located at:

/usr/lib/systemd/system /httpd.service

We can list all units managed by systemd with the following command

# systemctl list-units

Mainly we have service units, other units types though do exits such as targets. If we only want to list the service units we can add in an extra option:

# systemctl list-units --type service

If the web server was not already installed it is unlikely to be running, we can check the service status with systemctl. If the service is running we also see snippets from the logs.

# systemctl status httpd

We can also enable autostart of the service and start it now, enabling the service will ensure it starts on system start up and starting the service ensures it runs now.

# systemctl enable httpd
# systemctl start httpd

A disabled service can still be started by root, so to prevent accidental starting of a disabled service we can further control it by masking the service. I masked service has to be unmasked before starting it.

# systemctl stop httpd
# systemctl disable httpd
# systemctl mask httpd

We can also run less verbose test than status on a service:

# systemctl is-enabled httpd
# systemctl is-active httpd

The video steps you through the process: