Schedule a Rust server restart
Rust servers accumulate entity count relentlessly through a wipe cycle — every foundation, every sleeping bag, every dropped item is a thing the server simulates. Performance late in a wipe is measurably worse than at the start, and a daily restart claws back a useful amount of it.
When should it restart?
Use {{minutes}} where the countdown number should go.
What happens, in order
- Job startsWarn
say "Server restarting in 15 min" - 10 min beforeWarn
say "Server restarting in 10 min" - 5 min beforeWarn
say "Server restarting in 5 min" - 1 min beforeWarn
say "Server restarting in 1 min" - Restart timeSave
server.save - Restart timeStop
quit
quit saves before exiting. Rust writes large save files, so allow the process a minute to finish rather than following up with a kill.
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-rust.sh
The script it runs
Save as /opt/restart-rust.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 Rust.
# 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:-28016}"
: "${RCON_PASSWORD:?set RCON_PASSWORD before running}"
send() {
rcon-cli --host "$RCON_HOST" --port "$RCON_PORT" --password "$RCON_PASSWORD" "$1"
}
# 15 minute warning
send 'say "Server restarting in 15 min"'
sleep 300
# 10 minute warning
send 'say "Server restarting in 10 min"'
sleep 300
# 5 minute warning
send 'say "Server restarting in 5 min"'
sleep 240
# 1 minute warning
send 'say "Server restarting in 1 min"'
sleep 60
# Flush the world to disk
send 'server.save'
sleep 10
# Shut down cleanly
send 'quit'
# Give the process time to finish writing before anything restarts it.
sleep 30
systemctl start rust 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 Rust
Rust writes a large save file and takes real time doing it. Do not follow the quit with a kill or a container restart on a short timer; give the process at least a minute. The other thing to plan around is that a restart during peak hours empties a server — players who get disconnected mid-raid do not come back, so schedule for the quietest hour your population has.