Day 26intermediateFeb 26, 2026

Create and Manage Services with systemd

systemd lets you run your apps as managed services that start on boot, restart on failure, and log automatically.

linuxsystemdservices
Share:

What

systemd is the init system on most modern Linux distributions. It manages services (daemons) and lets you start, stop, enable, and monitor background processes with a unified interface. You define services using unit files that describe how your application should run.

Why It Matters

Running apps with nohup or screen is fragile β€” they don't restart on failure, don't start on boot, and logs scatter everywhere. systemd gives you automatic restarts, dependency management, resource limits, and centralized logging with journalctl. It's how production Linux services are managed.

Example

# Create a service unit file
# /etc/systemd/system/myapp.service
[Unit]
Description=My Application
After=network.target

[Service]
Type=simple
User=appuser
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node /opt/myapp/server.js
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target

# Reload systemd after creating/modifying the file
sudo systemctl daemon-reload

# Start, enable (auto-start on boot), and check status
sudo systemctl start myapp
sudo systemctl enable myapp
sudo systemctl status myapp

# View logs for the service
journalctl -u myapp -f
bash

Common Mistake

Forgetting to run 'systemctl daemon-reload' after creating or modifying a service file. Without it, systemd uses the old cached version of your unit file and your changes won't take effect.

Quick Fix

Make it a habit: every time you edit a .service file, immediately run 'sudo systemctl daemon-reload' before starting or restarting the service. You can chain them: sudo systemctl daemon-reload && sudo systemctl restart myapp.

Key Takeaways

  • 1Place unit files in /etc/systemd/system/ for custom services
  • 2Always run 'systemctl daemon-reload' after editing service files
  • 3Use 'systemctl enable' to start your service automatically on boot
  • 4Restart=on-failure makes your service self-healing
  • 5Use 'journalctl -u myapp -f' to tail service logs in real time

Was this tip helpful?

Help us improve the DevOpsPath daily collection

Share: