In this video, I work with systemd services on a Linux server: installing and managing Apache httpd, inspecting unit files, and creating a custom service that runs my own script and logs output.
I work on managing systemd services on Linux using Apache httpd as an example and then move on to creating my own custom service. I show how to progress from a simple package installation to inspecting unit files, wiring in a custom script, and configuring systemd to start it automatically and log its output.
Here’s what I do in this session:
Install the Apache httpd web server with dnf and control it with systemctl start and systemctl enable so it comes up at boot
Use netstat to verify that httpd is actually listening on the expected port
Explore how systemd organizes services by listing /etc/systemd/system/, multi-user.target.wants, and /usr/lib/systemd/system
Open and read the httpd.service unit file to see how a real production service is defined
Create a custom script in /usr/sbin/testscript.sh, make it executable, and verify that it runs and writes to /tmp and /var/log
Write a custom systemd unit file (/etc/systemd/system/test.service), reload the systemd daemon, start and enable the new service, and confirm that it logs as expected
This lab lines up closely with certification and real-world admin topics, such as:
CompTIA Linux+: Managing services with systemd, verifying network listeners, and troubleshooting service behavior
RHCSA / LFCS / LPIC-1: Working with unit files, enabling services at boot, and creating custom services with systemd
[ec2-user@ip-172-31-27-46 ~]$ history
1 history
2 clear
3 sudo dnf install httpd
4 sudo netstat -tnlp
5 sudo systemctl start httpd.service
6 sudo netstat -tnlp
7 sudo systemctl enable httpd
8 ls -ltrah /etc/systemd/system/multi-user.target.wants/
9 ls -ltrah /etc/systemd/system/
10 ls -ltrah /usr/lib/systemd/system
11 less /usr/lib/systemd/system/httpd.service
12 tail -n5 /usr/lib/systemd/system/httpd.service
13 sudo vi /usr/sbin/testscript.sh
14 ls -ltrah /usr/sbin/te*
15 sudo chmod a+x /usr/sbin/testscript.sh
16 ls -ltrah /usr/sbin/te*
17 ls -ltrah /tmp
18 cat /usr/sbin/testscript.sh
19 sudo /usr/sbin/testscript.sh
20 ls -ltrah /tmp
21 ls -ltrah /var/log
22 cat /var/log/26-01-15.log
23 clear
24 ls -ltrah /etc/systemd/system
25 ls -ltrah /etc/systemd/system/httpd.service.d/
26 sudo vi /etc/systemd/system/test.service
27 sudo systemctl deamon-reload
28 sudo systemctl daemon-reload
29 sudo systemctl start test_service
30 sudo systemctl start test
31 ls -ltrah /var/log
32 cat /var/log/26-01-15.log
33 sudo systemctl enable test.service
34 sudo systemctl start test
35 cat /var/log/26-01-15.log
36 history
[ec2-user@ip-172-31-27-46 ~]$ cat /etc/systemd/system/test.service
[Unit]
Description=A description for your custom service goes here
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /usr/sbin/testscript.sh
TimeoutStartSec=0
[Install]
WantedBy=default.target
[ec2-user@ip-172-31-27-46 ~]$ cat /usr/sbin/testscript.sh
#!/bin/bash
d=$(date +%y-%m-%d)
t=$(date +%y-%m-%d-%s)
echo "$t" **some characters are not allowed** /var/log/"$d".log
exit 0
#Linux #systemd #httpd #Apache #SysAdmin #RHCSA #LinuxPlus #LFCS #LPIC1