9.3 Systemd
Systemd is a suite of basic building blocks for a Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system.
Systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, maintains mount and automount points, and implements an elaborate transactional dependency-based service control logic.
Other parts include a logging daemon, utilities to control basic system configuration like the hostname, date, locale, maintain a list of logged-in users and running containers and virtual machines, system accounts, runtime directories and settings, and daemons to manage simple network configuration, network time synchronization, log forwarding, and name resolution.
Runtime and Configuration
With many topics during the exam, they will ask you to make your changes persistent. This means that changes persist after a reboot.
To have a process start up after a reboot, we must enable the process.
To start the process, we must start the process.
So, if you want to install a webserver you want to both interact with and make part of the configuration of Linux, you need to both start and enable the process.
Checking Process status
Let’s take the webserver process nginx and do a small experiment.
dnf install nginx -y
End message should be:
Installed:
nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
Complete!
Next, let’s check the status:
systemctl status nginx
[root@rhcsa ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
First, observe the permanent status at the /usr/lib/systemd/system/nginx.service; disabled; part. this means the process is not enabled in the configuration, meaning it is not going to start after a reboot. This also shows us where this configuration is located /usr/lib/systemd/system/nginx.service. You can check it out with the cat command.
There is also the vendor preset: disabled which means that the disabled state is the default after installation.
Secondly, check the current status at the Active: inactive (dead) part. This means the process has not started yet and therefore, it is not part of the runtime either.
Let’s change that.
Start and Enable a service / process
There are 3 ways to start and enable a service.
Option 1:
systemctl start nginx
Followed by the command:
systemctl enable nginx
Option 2 as a one-liner:
systemctl start nginx; systemctl enable nginx
Option 3 as one command:
systemctl enable nginx --now
Results can be checked with:
systemctl status nginx
[root@rhcsa ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-07-21 16:20:03 EDT; 7s ago
Process: 646479 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 646474 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 646472 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 646480 (nginx)
Tasks: 3 (limit: 4631)
Memory: 6.4M
CGroup: /system.slice/nginx.service
├─646480 nginx: master process /usr/sbin/nginx
├─646481 nginx: worker process
└─646482 nginx: worker process
Jul 21 16:20:03 rhcsa.greateracademy.local systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jul 21 16:20:03 rhcsa.greateracademy.local nginx[646474]: nginx: the configuration file /etc/nginx/nginx.conf syntax is>
Jul 21 16:20:03 rhcsa.greateracademy.local nginx[646474]: nginx: configuration file /etc/nginx/nginx.conf test is succe>
Jul 21 16:20:03 rhcsa.greateracademy.local systemd[1]: Started The nginx HTTP and reverse proxy server.
Now check the changes in the status of the fields we previously looked at:
permanent status This has changed to enabled which means this process will start after a reboot.
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled;
current status This has changed to active (running) which means the process is currently started and active (part of the runtime). You can also see the date and time it was started, and how long ago this was.
Active: active (running) since Tue 2020-07-21 16:20:03 EDT; 7s ago
To check that the webserver is real:
curl 127.0.0.1
or
curl localhost
The curl command will download the url/website site data.
The IP 127.0.0.1 means localhost, aka this machine.
You should get some http data concerning the nginx manual page ending with:
Red Hat, Inc. website</a>. The documentation for Red Hat Enterprise Linux is <a href="http://www.redhat.com/docs/manuals/enterprise/">available on the Red Hat, Inc. website</a>.</p>
</div>
</div>
<div class="logos">
<a href="http://nginx.net/"><img
src="nginx-logo.png"
alt="[ Powered by nginx ]"
width="121" height="32" /></a>
<a href="http://www.redhat.com/"><img
src="poweredby.png"
alt="[ Powered by Red Hat Enterprise Linux ]"
width="88" height="31" /></a>
</div>
</div>
</body>
</html>