0
0
Linux CLIscripting~30 mins

Startup and init systems (systemd) in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic systemd Service Setup and Management
📖 Scenario: You are managing a Linux server and want to create a simple service that runs a custom script at startup using systemd. This will help you automate tasks when the system boots.
🎯 Goal: Create a basic systemd service file to run a script at startup, enable the service, and check its status.
📋 What You'll Learn
Create a script file with a simple echo command
Create a systemd service file with correct sections and directives
Enable the service to start at boot
Start the service manually
Check the service status
💡 Why This Matters
🌍 Real World
Automating tasks on Linux servers or desktops to run scripts or programs at system startup.
💼 Career
System administrators and DevOps engineers often create and manage systemd services to control software and scripts on Linux systems.
Progress0 / 4 steps
1
Create the startup script
Create a file called /usr/local/bin/startup_script.sh with the content #!/bin/bash on the first line and echo "Startup script running" on the second line. Make sure the script is executable by running chmod +x /usr/local/bin/startup_script.sh.
Linux CLI
Need a hint?

Use a text editor like nano or vim to create the file, then run chmod +x /usr/local/bin/startup_script.sh to make it executable.

2
Create the systemd service file
Create a file called /etc/systemd/system/startup_script.service with the following content: under the [Unit] section, add Description=Startup Script Service; under the [Service] section, add ExecStart=/usr/local/bin/startup_script.sh; under the [Install] section, add WantedBy=multi-user.target.
Linux CLI
Need a hint?

Use a text editor to create the service file with the exact sections and lines as described.

3
Enable and start the service
Run the commands systemctl enable startup_script.service to enable the service at boot and systemctl start startup_script.service to start the service immediately.
Linux CLI
Need a hint?

Use systemctl enable to set the service to run at boot and systemctl start to run it now.

4
Check the service status
Run the command systemctl status startup_script.service and observe the output. The output should include the line Active: active (running) indicating the service is running.
Linux CLI
Need a hint?

Use systemctl status startup_script.service to see if the service is running.