Automatic restarts for a Valheim server
A Valheim server does run better with the occasional restart after long uptimes, but the game offers almost no tools for doing it nicely. The dedicated server has no remote console of any kind.
When should it restart?
Valheim has no remote console, so no script can warn players or tell the server to save. All that remains is a clean process signal, which this game does honour properly. That is why the schedule below fires at exactly the time you chose, with no lead time: there is no countdown to wait for.
What happens, in order
- Restart timeStopSend SIGTERM to the process, then let it exit by itself
Valheim’s dedicated server has no remote console, so there is no way to warn players from a script and no save command to send. The restart is a clean process signal and nothing else — which the server does handle correctly, saving the world as it shuts down.
The crontab line
No head start required — nothing counts down before the restart.
0 4 * * * /opt/restart-valheim.sh
The script it runs
Save it as /opt/restart-valheim.sh and mark it executable. It expects rcon-cli on the path and takes the password from an environment variable instead of storing it in the file.
#!/usr/bin/env bash set -euo pipefail # Scheduled restart for Valheim. # Generated by spawnbench.com/restart-scheduler sleep 10 # Valheim has no console, so stop it the way its service manager would. systemctl restart valheim || pkill -TERM -f valheim
Heads up: cron follows the server clock, not your local time. Check with timedatectl first. A container set to UTC and an admin living in Europe differ by two hours in summer and by one in winter, so 04:00 may not be the 04:00 you had in mind.
Advertisement
What is different about Valheim
A script cannot warn players, and there is no save command to send. What Valheim does get right is saving on a clean shutdown, so SIGTERM — the signal a systemctl restart sends — leaves the world safe. Avoid any kill signal that bypasses that, and do not schedule restarts while people play, since the disconnect will be the first warning they get.
Advertisement