Menu
 

Configuring Automated Restarts for Sons of the Forest Servers

Configuring Automated Restarts for Sons of the Forest Servers

Sons of the Forest's dedicated server process is known to accumulate memory over long sessions—particularly after many player join/leave cycles or after the world's cannibal AI runs through multiple full day-night cycles. A structured automated restart schedule keeps RAM usage in check and gives the server a clean state. Without it, you may see latency increase steadily until the next manual intervention.

🕐 Recommended Frequency

Most community servers restart once every 24 hours (typically at 4–6 AM to hit the lowest online window). High-population (8+ player) servers may benefit from a 12-hour cycle.

💾 Save Before Restart

Always trigger a clean world save before shutting down. A bare kill without a prior save can roll back the last 5–10 minutes of progress for all players.

Method 1: systemd Timer (Linux — Recommended)

The cleanest way to automate server restarts on Linux is via a systemd service + timer pair. This gives you crash recovery, clean logging, and full control over the restart window.

Step 1 — Create the service file

# /etc/systemd/system/sotf.service
[Unit]
Description=Sons of the Forest Dedicated Server
After=network.target

[Service]
Type=simple
User=steam
WorkingDirectory=/home/steam/sotf
ExecStart=/home/steam/sotf/SonsOfTheForestDS
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target

Step 2 — Create the timer file

# /etc/systemd/system/sotf-restart.timer
[Unit]
Description=Daily SOTF Server Restart

[Timer]
# Restart every day at 05:00 server time
OnCalendar=*-*-* 05:00:00
Persistent=true

[Install]
WantedBy=timers.target

Step 3 — Create the restart service

# /etc/systemd/system/sotf-restart.service
[Unit]
Description=Restart Sons of the Forest Server

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart sotf.service

Step 4 — Enable and start

sudo systemctl daemon-reload
sudo systemctl enable sotf.service sotf-restart.timer
sudo systemctl start sotf.service sotf-restart.timer

# Verify timer is scheduled:
systemctl list-timers --all | grep sotf

Method 2: Cron Job (Simple Alternative)

If you prefer a quick solution without systemd units:

# Edit root crontab:
sudo crontab -e

# Restart SOTF every day at 05:00
0 5 * * * systemctl restart sotf.service

Method 3: Windows Task Scheduler

On Windows hosts, use PowerShell with Task Scheduler:

# PowerShell script: restart-sotf.ps1
Stop-Process -Name "SonsOfTheForestDS" -Force
Start-Sleep -Seconds 5
Start-Process "C:\sotf\SonsOfTheForestDS.exe"

Then in Task Scheduler → Create Basic Task → Daily → 5:00 AM, point the action to run powershell.exe -File C:\scripts\restart-sotf.ps1.

Pre-Restart RCON Warning

Notify players before the restart using an RCON broadcast. Wrap the restart with this shell script:

#!/bin/bash
# warn-and-restart.sh

RCON_PASS="yourpassword"
RCON_PORT=9876

# Send a 5-minute warning
rcon -p $RCON_PASS -P $RCON_PORT broadcast "⚠️ Server restarting in 5 minutes for maintenance!"
sleep 240

# 1-minute final warning
rcon -p $RCON_PASS -P $RCON_PORT broadcast "⚠️ Server restarting in 1 minute. Please find a safe spot!"
sleep 60

# Graceful shutdown
systemctl stop sotf.service
sleep 5
systemctl start sotf.service

Pro Tip: Create a dedicated steam user (non-root) to run the server process. Automated restarts run as this user will have the minimum permissions needed and are safer than running as root.

Monitoring for Crash Recovery

With the systemd service's Restart=on-failure directive, the server will automatically recover from unexpected crashes as well—not just scheduled restarts. Check crash history with:

journalctl -u sotf.service --since "24 hours ago" | grep -i "error\|crash\|failed"

Professional Hosting

Want automatic restart scheduling handled for you? Host your Sons of the Forest server with Supercraft and configure scheduled restarts, RCON broadcasts, and crash recovery from our control panel with zero scripting required.

Top