Schedule a Project Zomboid server restart
Zomboid keeps explored chunks resident and the memory footprint of a long-running server climbs steadily with how far your players have travelled. A restart is the only thing that brings it back down.
When should it restart?
Use {{minutes}} where the countdown number should go.
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
Shifted 15 minutes earlier than your chosen time, so the restart itself lands on it rather than 15 minutes after.
45 3 * * * /opt/restart-project_zomboid.sh
The script it runs
Save as /opt/restart-project_zomboid.sh and make it executable. It assumes rcon-cli is on the path and reads the password from the environment rather than embedding it.
#!/usr/bin/env bash
set -euo pipefail
# Scheduled restart for Project Zomboid.
# Generated by spawnly.net/tools/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 || trueCron uses the server’s timezone, not yours. Check it with timedatectl before assuming 04:00 means 04:00 where you are — a container in UTC and an admin in Europe are two hours apart in summer and one in winter.
The part specific to Project Zomboid
The save can take considerably longer than you expect on a well-explored map, so leave real time between the save and the stop. Zomboid is also unusually punishing about disconnections — a player killed by a disconnect stays dead — which makes the choice of restart hour more consequential here than in most games. Pick genuine dead hours.