Automatic restarts for a Project Zomboid server
Zomboid holds explored chunks in memory, so a server that has been up for a long time keeps growing in step with how far players have roamed. Only a restart brings the number back down.
When should it restart?
Put {{minutes}} wherever the number of minutes left should appear.
What happens, in order
- Job startsWarn
servermsg "Server restarting in 15 min" - 10 min beforeWarn
servermsg "Server restarting in 10 min" - 5 min beforeWarn
servermsg "Server restarting in 5 min" - 1 min beforeWarn
servermsg "Server restarting in 1 min" - Restart timeSave
save - Restart timeStop
quit
quit saves and exits cleanly. Zomboid keeps a lot of loaded chunks in memory on a well-explored map, so the save can take noticeably longer than you expect.
The crontab line
Moved 15 minutes ahead of the time you picked, so the restart happens at that time instead of 15 minutes later.
45 3 * * * /opt/restart-project_zomboid.sh
The script it runs
Save it as /opt/restart-project_zomboid.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 Project Zomboid.
# Generated by spawnbench.com/restart-scheduler
# The password stays out of this file. Put it in the environment, or in a
# file only root can read, and export it before this script runs.
RCON_HOST="${RCON_HOST:-127.0.0.1}"
RCON_PORT="${RCON_PORT:-27015}"
: "${RCON_PASSWORD:?set RCON_PASSWORD before running}"
send() {
rcon-cli --host "$RCON_HOST" --port "$RCON_PORT" --password "$RCON_PASSWORD" "$1"
}
# 15 minute warning
send 'servermsg "Server restarting in 15 min"'
sleep 300
# 10 minute warning
send 'servermsg "Server restarting in 10 min"'
sleep 300
# 5 minute warning
send 'servermsg "Server restarting in 5 min"'
sleep 240
# 1 minute warning
send 'servermsg "Server restarting in 1 min"'
sleep 60
# Flush the world to disk
send 'save'
sleep 10
# Shut down cleanly
send 'quit'
# Give the process time to finish writing before anything restarts it.
sleep 30
systemctl start project_zomboid 2>/dev/null || trueHeads 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 Project Zomboid
On a map that has been explored thoroughly, saving can take much longer than you would guess, so put a proper gap between the save and the stop. Zomboid is also harsh about disconnects — a character that dies during one stays dead — so the hour you choose matters more here than in most games. Choose one when truly nobody is on.
Advertisement
Setting up RCON
The warnings and the stop go over RCON, configured in the server's .ini with RCONPort (27015 by default) and RCONPassword. Set the password before relying on RCON; it is the only thing protecting a console that can stop the server. The script talks to it from the same machine, so the port never needs to be forwarded.
Restarts keep mods current
Workshop mods are only downloaded when the server starts. When a mod updates, players who have the new version cannot join a server still running the old one, which is the most common reason a modded Zomboid server suddenly refuses everyone. A daily restart picks up overnight mod updates before the evening's players arrive.
Do not rely on the shutdown save
With SaveWorldEveryMinutes left at 0, the only save happens when the server stops. A scheduled restart makes that safe night after night, but a crash between restarts loses everything since the last one. Set a save interval, and use BackupsPeriod for periodic backups, so the restart is not your only safety net.