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.

Начальный5 minОбновлено:13 сентября 2026 г.
Проверено: systemd 247+OS Ubuntu / Debian / Rocky
На этой странице
Your Own Server (Advanced) руководства

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

Частые вопросы

Why do changes to a service file not take effect immediately?

Systemd does not automatically detect file edits on disk. You must run 'systemctl daemon-reload' after modifying unit files and then restart the service.

How can I see why my application crashed?

You can inspect the most recent logs with 'journalctl -u service-name.service -e'. Add the '-f' flag to tail logs in real time.

Does Restart=always cause an infinite crash loop?

If the application has a persistent bug, it will continuously crash and restart. You should add a delay such as 'RestartSec=5' to prevent rapid restart loops.

Было ли руководство полезным?

Отзыв сразу попадает команде, которая ведёт это руководство.

Не нашли решение?

Вы можете открыть обращение в службу поддержки из панели.

Открыть обращение