Beginner5 minUpdated: 2026-09-13
Creating Auto-Restarting Background Services with Systemd
How to configure systemd unit files to automatically restart Node.js, Python, Go, or game scripts on reboot and crash.
Verified against
- systemd
- 247+
- OS
- Ubuntu / Debian / Rocky
- Last checked
- 2026-09-13
Before you start
- Root or sudo access
- An application that already runs correctly when started by hand
All Guides
Reading progress
Running an app directly in a terminal terminates when the SSH session closes. To keep applications running 24/7, restart on crashes, and auto-boot on server reboot, modern Linux distributions use systemd units.
1. Writing the Service File#
/etc/systemd/system/uygulamam.service
[Unit]
Description=Benim Node.js Uygulamam
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/app
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=5
Environment=NODE_ENV=production PORT=3000
[Install]
WantedBy=multi-user.target2. Enabling the Service and Live Log Streaming#
Sunucu Terminali
sudo systemctl daemon-reload
sudo systemctl enable --now uygulamam.service
# Canlı log akışı:
sudo journalctl -u uygulamam.service -fWas this guide helpful?
Feedback goes straight to the team that maintains this guide.
Related Guides
Initial Security Hardening for Linux VDS/VPS Servers
Essential hardening checklist for fresh Ubuntu/Debian servers: SSH keys, UFW firewall, and fail2ban brute-force defense.
Container Management with Docker and Docker Compose on Linux
Install official Docker Engine on Ubuntu/Debian, write compose specifications, and isolate cloud workloads.

