Schedule a 7 Days to Die server restart

A 7 Days to Die server's memory use tracks how much of the map has been explored and how much has been built, and neither of those goes down. Restarting daily keeps the server responsive through a long playthrough, which matters most on the horde nights that everyone actually shows up for.

When should it restart?

Use {{minutes}} where the countdown number should go.

What happens, in order

  1. Job startsWarnsay "Server restarting in 15 min"
  2. 10 min beforeWarnsay "Server restarting in 10 min"
  3. 5 min beforeWarnsay "Server restarting in 5 min"
  4. 1 min beforeWarnsay "Server restarting in 1 min"
  5. Restart timeSavesaveworld
  6. Restart timeStopshutdown

The console here is telnet rather than RCON. Reach it over an SSH tunnel or from the machine itself — the telnet port must not be forwarded, because it authenticates with a password in clear text.

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-seven_days_to_die.sh

The script it runs

Save as /opt/restart-seven_days_to_die.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 7 Days to Die.
# 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:-8081}"
: "${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 'saveworld'

sleep 10
# Shut down cleanly
send 'shutdown'

# Give the process time to finish writing before anything restarts it.
sleep 30
systemctl start seven_days_to_die 2>/dev/null || true

Cron 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 7 Days to Die

The console here is telnet, not RCON, and telnet sends its password in clear text. Run the script on the server itself, or reach the port through an SSH tunnel — never by forwarding it. Time the restart away from day seven and its multiples: a restart landing in the middle of a blood moon is the worst possible moment, and the schedule will not know that unless you plan it.

Support & Help