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.

Principiante5 minActualizado:13 de septiembre de 2026
Verificado: systemd 247+OS Ubuntu / Debian / Rocky

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.target

2. 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 -f

¿Te ha resultado útil esta guía?

Los comentarios van directamente al equipo que mantiene esta guía.

¿No encontró una solución?

Puede abrir una solicitud al equipo de soporte desde el panel.

Abrir una solicitud