#134: Introduction to Systemd and Lab 2.1 Tasks - Rmhibbert/oe2-group-c GitHub Wiki

Step by step

Create Script

Description: Create a script called hello.sh inside group-c

Command: sudo nano hello.sh


Add example code

Description: Add the example code into hello.sh

Command: #!/bin/bash while $(sleep 30); do echo "Hello, systemd world" done


Change permission

Description: Change the permission of the script

Command: sudo chmod +x ~/hello.sh


Find folder

Description: After create the hello.sh script, find the file path to system

Command: cd /etc/systemd/system


Create a service script

Description: After you have find the system path create a new service called hello.service, and added the example code into the script

Command: [Unit] Description=Hello world service After=systemd-user-sessions.service [Service] SyslogIdentifier=HelloWorldService Type=simple ExecStart=/home/group-c/hello.sh


Vertify the file

Description: Verify that systemd recognises the service that we just created

Command: systemctl list-unit-files | grep hello.service


Startup the service

Description: After vertify that the file is recognises, run the service

Command: systemctl start hello.service

image


Check the service status

Description: After the Authentication is complete and the service is running, check the status of the service

Command: systemctl status hello.service

image


Add yourself to group

Description: Add yourself to the systemd-journal group

Command: sudo usermod -aG systemd-journal $(whoami)


Write the log

Description: After check the status, you can see the log of the file by running this command

Command: journalctl -u hello -e

image


Challenges

I was struggling with the authentication when trying to startup the hello.service script, but I have manage to fix it due to the code inside the script.