How to restart a Minecraft server on a schedule
Servers that run for days can slowly use more memory, accumulate stray entities and pick up small glitches from plugins. A regular restart clears all of that. Many servers restart once a day at a quiet hour. Done well, players hardly notice, because they get a warning and the server is back in a minute.
Do you need one?
Not always. A small server for friends that is restarted whenever you update something may never need a schedule. A busy public server, or one with many plugins, usually benefits from a daily restart. Pick an hour when few people are online, and tell players the time.
Warn players first
Nobody likes being thrown off. Send messages in the chat a few minutes before the restart, for example at five minutes, one minute and ten seconds:
/say The server will restart in 5 minutes.
/say The server will restart in 1 minute.
/say Restarting in 10 seconds.
Then run /stop. On a plain setup nothing brings the server back by itself, which is the next part.
Bringing it back
A restart is a stop followed by a start, and something has to do the start.
- On a machine you manage, run the server under something that restarts it when it ends: a systemd service with
Restart=always, or a loop in your start script. Then a cron job or timer can send the warnings andstopat the chosen time. - Paper's own
/restartonly works ifrestart-scriptis set inspigot.ymlto a script that starts the server again. - A plugin can do the whole thing, from warnings to the restart, in the game.
- A host usually has a schedule in its panel.
A systemd example
A service that starts again after any stop:
[Service]
WorkingDirectory=/srv/minecraft
ExecStart=/usr/bin/java -Xms4G -Xmx4G -jar server.jar nogui
Restart=always
RestartSec=5
A timer or cron entry can then stop it at the scheduled hour with a warning script, and systemd starts it again.
Make sure the world is saved
A normal /stop saves the world first. Avoid killing the process, because that can lose recent changes. A restart is a good moment for a backup too, see how to back up a world.
On Saryno
Open the server, go to Settings, and choose the restart times. Players get a friendly warning first, and the server comes back by itself. Scheduled restarts are only needed for servers that stay awake, since the free server sleeps and wakes with a fresh state whenever it is empty.