Some software is meant to run forever: chat bots, queue workers, websocket and game servers, trading systems, crawlers, data collectors and IoT backends. Keeping them running for a day is easy. Keeping them running for months, through crashes, memory leaks, growing logs, network hiccups and operating-system updates, needs a little engineering. A VPS is ideal for this: it is always on, and you control everything.
1. Supervise the Process
# /etc/systemd/system/collector.service
[Unit]
Description=Data collector
After=network-online.target
Wants=network-online.target
[Service]
User=collector
WorkingDirectory=/srv/collector
ExecStart=/srv/collector/venv/bin/python main.py
Restart=always
RestartSec=5
StartLimitIntervalSec=300
StartLimitBurst=10
MemoryMax=2G
TimeoutStopSec=60
[Install]
WantedBy=multi-user.target
sudo systemctl enable --now collector
systemctl status collector
journalctl -u collector -f
Restart=alwaysbrings it back after crashes;StartLimit*stops a crash loop from restarting forever every five seconds.MemoryMaxstops a leak from taking the whole server down.After=network-online.targetwaits for networking at boot.
Do not rely on screen, tmux or nohup for production processes; they do not restart after a crash or a reboot.
2. Handle Shutdown Gracefully
systemd and Docker send SIGTERM before stopping a process. Catch it, stop accepting new work, finish or checkpoint the current task, close connections and exit. Then updates and restarts lose nothing. TimeoutStopSec sets how long the process has before it is killed.
3. Detect "Running but Stuck"
The worst failure is a process that is alive but doing nothing: a deadlock, a lost connection that never reconnects, a blocked API call with no timeout. Supervisors cannot see that. Add one of:
- A heartbeat: the app pings a monitoring URL every few minutes; you are alerted if pings stop (push monitors in Uptime Kuma or similar).
- A health endpoint that reports the time of the last successful unit of work.
- systemd watchdog: with
WatchdogSec=, the app must notify systemd periodically or it is restarted.
Also set timeouts on every network call and reconnect with exponential backoff.
4. Watch for Memory Leaks
Small leaks only show up over days. Track memory per process over time:
systemctl status collector | grep Memory
ps -o pid,rss,etime,cmd -C python
Graph it in your monitoring system (see our monitoring guide). If memory climbs steadily, find the leak; as a stopgap, a scheduled restart during quiet hours keeps it contained, and many worker libraries support restarting after a number of jobs.
5. Keep Logs from Filling the Disk
A process that logs a line per event writes gigabytes over months. Send output to journald and cap it (SystemMaxUse=1G in journald.conf), or rotate log files with logrotate. Log at info level in production, and avoid logging full payloads.
6. Persist State
Restarts will happen, so store anything you cannot recompute: progress markers, cursors, queues and caches you rely on. Use a database, Redis with persistence, or atomic file writes (write to a temporary file, then rename). On restart, resume from the last checkpoint.
7. Plan for Updates and Reboots
- Automatic security updates install packages, but kernel updates need a reboot to take effect.
- Check
/var/run/reboot-requiredand reboot during a quiet window, monthly or as advisories require. - With proper supervision and graceful shutdown, a reboot is a short, routine interruption.
- If the service cannot tolerate any interruption, run two instances on separate servers.
8. Time and Scheduling
Long-running processes that schedule work internally should use monotonic clocks for intervals and store timestamps in UTC. Keep the server clock synchronised (timedatectl shows whether NTP is active). For simple periodic tasks, systemd timers or cron may be more robust than an in-process scheduler (see our cron guide).
Typical Long-Running Workloads
| Workload | Key concern |
|---|---|
| Discord or Telegram bots | Reconnect after gateway disconnects; rate limits |
| Queue workers | Graceful shutdown, retries (see our workers guide) |
| WebSocket servers | Many open connections; file descriptor limits (LimitNOFILE) |
| Trading systems | Clock accuracy, reconnects, restarts outside market hours |
| Crawlers and collectors | Checkpointing progress; politeness limits |
| Game servers | Scheduled restarts and world backups |
Sizing
Size for steady-state memory plus growth over time, not just startup memory. Several small bots and workers fit on 2 vCores / 8 GB; processes holding large in-memory datasets or many connections need 16 GB or more. Keep a swap file as a safety net (see our swap guide).
Deploying Updates to Always-On Processes
Deploy new code into a new directory, then restart the service so it gracefully stops the old version and starts the new one. For processes holding many client connections, such as websocket servers, clients should reconnect automatically after the brief interruption. Keep the previous version on disk for a quick rollback, and avoid deploying during the busiest hours for services that cannot run two instances at once.
The Same Ideas in Docker
In Docker Compose, use restart: unless-stopped, set mem_limit, add a healthcheck that tests real progress, and give the container a stop_grace_period long enough to finish work after SIGTERM. Configure Docker's log driver with size limits (max-size and max-file) so container logs cannot fill the disk (see our Docker guide).
Alerts Worth Having
- The heartbeat stopped arriving.
- The service restarted more than a few times in an hour.
- Memory use is close to the service limit.
- Disk usage passed 80%.
Checklist for Always-On Processes
- Runs as a supervised service with restart limits and a memory cap.
- Handles SIGTERM and checkpoints its state.
- Has a heartbeat or health check with alerts.
- Logs are capped and rotated.
- Network calls have timeouts and reconnect with backoff.
- Reboots and deploys have been tested.
- Someone knows where the service runs, how to restart it and where its logs and backups are.
Work through the list once for every new always-on service before calling it production-ready; it takes minutes and prevents most night-time surprises.
SkyRainCloud Plans for This Workload
Long-running processes need steady memory more than burst CPU. The 2 vCore / 8 GB plan runs several bots or workers; choose 4 vCores / 16 GB or more when processes hold large datasets in memory or you run many of them.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.
Frequently Asked Questions
How do I keep an application running 24/7 on a VPS?
Restart=always, or as a Docker container with a restart policy, so it starts at boot and restarts after crashes.Why not use screen or nohup?
How do I detect a process that is running but stuck?
How do I stop a memory leak crashing my server?
MemoryMax on the service, monitor memory over time, fix the leak, and schedule restarts as a temporary measure.Will reboots break my long-running app?
How often should I reboot?
How do I prevent logs from filling the disk?
SystemMaxUse or logrotate for files, and avoid logging large payloads.How do I handle many open connections?
LimitNOFILE in the service unit and size memory for the connections.