🚀Day 12 – Systemd and Linux Services

Ritesh SinghRitesh Singh
2 min read

Welcome to Day 11 of my 100 Days of DevOps journey!
Today, I explored how to manage services in Linux using systemd. This is a crucial skill for maintaining and deploying applications in production environments.


🧠 What is systemd?

systemd is the modern init system for most Linux distributions. It handles:

  • Boot process

  • Background services (daemons)

  • Logging with journald

  • Resource control and service dependencies


🔧 Common Commands

TaskCommand
Check service statussystemctl status nginx
Start a servicesudo systemctl start nginx
Stop a servicesudo systemctl stop nginx
Restart a servicesudo systemctl restart nginx
Enable on bootsudo systemctl enable nginx
Disable on bootsudo systemctl disable nginx
Reload daemon configssudo systemctl daemon-reload

🛠️ Real Example: Custom Background App with systemd

✅ Step 1: Create a Simple Script

mkdir -p ~/myapp
nano ~/myapp/app.sh

Paste:

#!/bin/bash
while true; do
  echo "$(date) - My custom app is running..." >> /home/ritesh/myapp/app.log
  sleep 10
done

Make it executable:

chmod +x ~/myapp/app.sh

✅ Step 2: Create a Systemd Unit File

sudo nano /etc/systemd/system/myapp.service

Paste:

[Unit]
Description=My Custom App Service
After=network.target

[Service]
ExecStart=/home/ritesh/myapp/app.sh
Restart=always
User=ritesh

[Install]
WantedBy=multi-user.target

✅ Step 3: Start and Enable the Service

sudo systemctl daemon-reload
sudo systemctl start myapp.service
sudo systemctl enable myapp.service

🔍 Step 4: Check Logs and Status

systemctl status myapp.service
journalctl -u myapp.service -f
tail -f ~/myapp/app.log

❌ Step 5: Stop and Clean Up

sudo systemctl stop myapp.service
sudo systemctl disable myapp.service
sudo rm /etc/systemd/system/myapp.service
sudo systemctl daemon-reload

📌 Summary

✅ Learned systemd and unit file structure
✅ Created a persistent, restartable custom service
✅ Managed logs and service status with journalctl and systemctl
✅ Prepared for production-level Linux service management


📚 References:


🔗 GitHub Repo: DevOps Journal
✍️ Hashnode Blog: Day 12– Systemd and Linux Services

0
Subscribe to my newsletter

Read articles from Ritesh Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ritesh Singh
Ritesh Singh

Hi, I’m Ritesh 👋 I’m on a mission to become a DevOps Engineer — and I’m learning in public every single day.With a full-time commitment of 8–10 hours daily, I’m building skills in: ✅ Linux✅ Git & GitHub✅ Docker & Kubernetes✅ AWS EC2, S3✅ Jenkins, GitHub Actions✅ Terraform, Prometheus, Grafana I post daily blogs on Hashnode, push projects to GitHub, and stay active on LinkedIn and Twitter/X. Let’s connect, collaborate, and grow together 🚀 #100DaysOfDevOps #LearningInPublic #DevOps