Skip to content

Self HostingGuide

How to Set Up Auto Restart on a Minecraft Server

  • Updated
  • 14 min read
  • VPS Lane Engineering
Short answer

On Linux, run the server as a systemd service with Restart=on-failure and a daily timer. On Windows, start it from a looping batch file.

How we tested this

Run for real on Ubuntu 24.04.5 LTS with systemd 255 (255.4-1ubuntu8.19), OpenJDK 25.0.5.1, Minecraft Java Edition server 26.3 and Paper 26.3 build 273, inside a systemd container with its own network namespace. Every Linux output on this page comes from that machine, with the hostname mc01. tmux 3.4 session commands were checked on the host. Not run: the Windows batch file and Task Scheduler commands, which follow the Microsoft documentation under Sources, game panel steps, Fabric, Forge and NeoForge, and Bedrock Dedicated Server.

Minecraft Auto Restart Methods Compared

Minecraft auto restart methods differ in what they catch: a crash, a planned daily restart, or both.

This guide covers Minecraft Java Edition servers. Bedrock Dedicated Server starts differently and needs its own setup.

Ways to auto restart a Minecraft server
MethodAfter a crashDaily restart with warningsCrash loop limitBest for
systemd service and timerYesYes, with the timer belowYesA Linux VPS or dedicated server with root
Loop script in tmux or screenYes, after any exitNeeds a plugin, mod or cron jobNoLinux without root access
Windows batch loopYes, after any exitNeeds a plugin or modNoA Windows PC or Windows server
Restart plugin or modOnly with a script, loop or panel behind itYesDepends on the add-onPaper, Forge and NeoForge servers
Game panel scheduleDepends on the panelYesDepends on the panelRented game server slots

Crash recovery and a scheduled restart are separate jobs. Crash recovery starts a server that died. A scheduled restart stops a healthy server on purpose at a quiet hour. This guide sets up both, and they work side by side.

The steps are written for the Java Edition server, vanilla or Paper, on Linux distributions that boot with systemd, such as Ubuntu and Debian, and were tested on Ubuntu 24.04. The backoff settings near the end need systemd 254 or newer, which you can check with systemctl --version.

Before You Set Up Auto Restart

Before you set up auto restart, make sure the server starts by hand, runs as its own user and has a fresh backup.

  • Root or sudo access on the server, because the unit files go in /etc/systemd/system.
  • systemd as the init system. ps -p 1 -o comm= should print systemd. Some container-based plans do not have it, and there you use the loop script instead. A Minecraft VPS with root access runs a full systemd.
  • The right Java version for your server release. Mojang lists Java 25 for Minecraft 26.3, and older releases need other versions. A Java that is too old makes every start fail, which is the crash loop shown later.
  • SSH access to the server. If it is not set up yet, see how to enable SSH on Ubuntu Server.
  • The Minecraft EULA. Read it before you start the server, because you set eula=true only if you agree to its terms. The server should then reach Done when you start it by hand.

Create a Dedicated Minecraft User

A dedicated Minecraft user keeps the server away from root, so a bad plugin or exploit is limited to that account.

bash
sudo useradd --system --create-home --home-dir /opt/minecraft --shell /usr/sbin/nologin minecraft
sudo mkdir -p /opt/minecraft/server
sudo cp server.jar /opt/minecraft/server/

The server only runs after you accept the Minecraft EULA. Read the EULA first, then open eula.txt and write the line eula=true only if you agree to its terms. When eula.txt is missing, nano makes a new one for you.

bash
sudo nano /opt/minecraft/server/eula.txt
sudo chown -R minecraft:minecraft /opt/minecraft

Test the Server by Hand

Test the server by hand once before systemd takes over, so a wrong Java version, jar or EULA shows up now.

bash
sudo -u minecraft sh -c 'cd /opt/minecraft/server && exec /usr/bin/java -Xms1G -Xmx1G -jar server.jar --nogui'
Output on Ubuntu 24.04.5, other lines left out
[11:10:13] [Server thread/INFO]: Done (0.830s)! For help, type "help"
[11:10:21] [Server thread/INFO]: Stopping server
[11:10:21] [Server thread/INFO]: Saving worlds

Wait for Done, type stop, and continue only after the server has shut down cleanly. The first start generates the world, so it takes longer than later starts.

For Paper the steps match, apart from the name of its jar file. Fabric and recent Forge or NeoForge installs may start differently, for example from a run script the installer created, so copy the java command your installation actually uses into ExecStart and keep the rest of the service file.

Back Up the World First

Back up the world first, with the server stopped, so a mistake in the steps below cannot cost you your builds.

bash
sudo tar -czf /root/minecraft-backup-$(date +%F).tar.gz -C /opt/minecraft server
sudo tar -tzf /root/minecraft-backup-$(date +%F).tar.gz | grep -E 'level.dat$|server.properties$'
Output on Ubuntu 24.04.5
server/world/level.dat
server/server.properties

Seeing level.dat and server.properties in the list proves the archive holds the world and the settings. It does not prove the backup restores cleanly, so test a restore on a spare folder at least once. To roll back the whole change, stop and disable the service, delete the unit files and start the server the way you did before.

Create the Minecraft systemd Service

A Minecraft systemd service starts the server at boot, runs it as the minecraft user and brings it back when Java crashes.

This setup has three parts: a socket unit that gives the server a console input, a small stop script that shuts it down cleanly, and the service unit itself. No screen or tmux is involved, so systemd watches the Java process directly.

The Console Socket

The console socket is a named pipe (FIFO) at /run/minecraft.stdin that systemd connects to the server console input.

Create each file in this guide with an editor at the path shown in its label, then save it. For this one that is:

bash
sudo nano /etc/systemd/system/minecraft.socket
/etc/systemd/system/minecraft.socket
[Unit]
Description=Minecraft server console input
PartOf=minecraft.service

[Socket]
ListenFIFO=/run/minecraft.stdin
SocketUser=minecraft
SocketGroup=minecraft
SocketMode=0660
RemoveOnStop=true

SocketMode=0660 lets the minecraft user, members of the minecraft group and root write to the pipe. The default would be 0666, open to every local user. Anyone who can write to it can run any console command, including op and stop, so keep the group membership tight.

The Stop Script

The stop script sends stop to the console and waits up to 60 seconds for Java to exit.

bash
sudo nano /usr/local/bin/mc-stop
/usr/local/bin/mc-stop
#!/bin/sh
PID="$1"
CONSOLE=/run/minecraft.stdin

if [ -z "$PID" ] || ! kill -0 "$PID" 2>/dev/null; then
    exit 0
fi
if [ -p "$CONSOLE" ]; then
    printf 'stop\n' > "$CONSOLE"
fi
i=0
while kill -0 "$PID" 2>/dev/null && [ "$i" -lt 60 ]; do
    sleep 1
    i=$((i + 1))
done
bash
sudo chmod 755 /usr/local/bin/mc-stop

Two checks in it came from testing. systemd runs the stop command even when the server already exited on its own, and an earlier version that always wrote stop left the word in the pipe, where the next server read it. The script now quits when the process is gone. A stop sent while the server is still starting is rejected with "An unexpected error occurred", so the wait is capped and systemd then ends the server with SIGTERM, which in our test still saved the world.

The Service File

The service file holds the start command, the restart policy and the crash loop limit in one place.

bash
sudo nano /etc/systemd/system/minecraft.service
/etc/systemd/system/minecraft.service
[Unit]
Description=Minecraft server
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=600
StartLimitBurst=5

[Service]
Type=simple
User=minecraft
Group=minecraft
WorkingDirectory=/opt/minecraft/server
Sockets=minecraft.socket
StandardInput=socket
StandardOutput=journal
StandardError=journal
ExecStart=/usr/bin/java -Xms1G -Xmx1G -jar server.jar --nogui
ExecStop=/usr/local/bin/mc-stop $MAINPID
TimeoutStopSec=120
Restart=on-failure
RestartSec=10
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
What the important service lines do
LineWhat it does
Restart=on-failureRestarts after an unclean signal such as SIGKILL or a non-zero exit code, but not after a clean stop
RestartSec=10Waits 10 seconds before each restart. The systemd default is 100 ms
StartLimitIntervalSec=600 and StartLimitBurst=5Gives up after 5 starts inside 10 minutes, so a broken server does not restart forever
SuccessExitStatus=143Treats exit status 143 as a clean stop. In our test the Java 25 server exited normally with status 143 after SIGTERM, so without this line a forced stop would be marked failed
TimeoutStopSec=120Limits how long a stop may take before systemd forces it
-Xms1G -Xmx1GThe heap used in testing. Set it to what your server needs, such as -Xmx4G, and leave memory for the system

Start and Enable the Service

Start and enable the service in one command, so it runs now and again after every reboot.

bash
sudo systemd-analyze verify /etc/systemd/system/minecraft.service
sudo systemctl daemon-reload
sudo systemctl enable --now minecraft.service
systemctl status minecraft.service --no-pager
Output on Ubuntu 24.04.5
● minecraft.service - Minecraft server
     Loaded: loaded (/etc/systemd/system/minecraft.service; enabled; preset: enabled)
     Active: active (running) since Thu 2026-12-03 10:24:53 UTC; 25s ago
TriggeredBy: ● minecraft.socket
   Main PID: 2301 (java)
        CPU: 20.773s
     CGroup: /system.slice/minecraft.service
             └─2301 /usr/bin/java -Xms1G -Xmx1G -jar server.jar --nogui

active (running) and enabled together mean the server runs now and starts at boot. Silence from systemd-analyze verify means the file parsed. Neither proves players can join, so check the log for Done and connect once from a client.

Send Commands to the Minecraft Console

Minecraft console commands go into the pipe at /run/minecraft.stdin, and the replies land in the systemd journal.

This helper checks that the server runs before it writes, then prints the last few log lines.

bash
sudo nano /usr/local/bin/mc-cmd
/usr/local/bin/mc-cmd
#!/bin/sh
CONSOLE=/run/minecraft.stdin
if ! systemctl is-active --quiet minecraft.service || [ ! -p "$CONSOLE" ]; then
    echo "minecraft.service is not running, command not sent" >&2
    exit 1
fi
printf '%s\n' "$*" > "$CONSOLE"
sleep 1
journalctl -u minecraft.service -n 5 -o cat --no-pager
bash
sudo chmod 755 /usr/local/bin/mc-cmd
sudo mc-cmd list
Last line of the output
[10:21:29] [Server thread/INFO]: System chat: There are 0 of a max of 20 players online:

Follow the live console with journalctl -u minecraft.service -f. The check in the helper matters: writing straight to the path while the socket is stopped creates an ordinary file, and the next start then fails with "Failed to open FIFO /run/minecraft.stdin: File exists".

Restart on Failure or Restart Always

Restart=on-failure restarts the server only after a failure, while Restart=always also restarts it after a clean in-game stop.

The table shows what each policy did with real events on the test server. The exit code decides it, and several events that look like problems exit with code 0.

Tested restart behaviour on systemd 255 with Minecraft 26.3
EventHow it endedon-failurealways
stop typed in the console or in gameExit code 0Stays stoppedRestarts
Java killed with SIGKILL, like an out of memory killSignal 9RestartsRestarts
Port 25565 already taken"FAILED TO BIND TO PORT", exit code 0Stays stoppedRestarts, and fails again
Java too old for the server jarExit code 1Restarts until the start limitRestarts until the start limit
Paper /restart with no start.shExit code 0Stays stoppedRestarts
sudo systemctl stop minecraftStop requestedStays stoppedStays stopped

Pick on-failure when stop should mean stop, for example before maintenance. Pick always when your staff use /stop or Paper /restart as a restart button. In both cases systemctl stop stops it for good, as the systemd documentation states.

To switch to always without editing the main file, create an override with sudo systemctl edit minecraft.service and add these lines.

Override for minecraft.service
[Service]
Restart=always

Test Auto Restart After a Minecraft Crash

Test auto restart after a Minecraft crash by killing Java with SIGKILL and watching systemd start it again.

bash
sudo systemctl kill --signal=SIGKILL minecraft.service
sleep 15
journalctl -u minecraft.service --since "-16s" --no-pager | grep "systemd\["
systemctl show minecraft.service -p NRestarts
Output on Ubuntu 24.04.5
Dec 03 10:25:18 mc01 systemd[1]: minecraft.service: Sent signal SIGKILL to main process 2301 (java) on client request.
Dec 03 10:25:18 mc01 systemd[1]: minecraft.service: Main process exited, code=killed, status=9/KILL
Dec 03 10:25:18 mc01 systemd[1]: minecraft.service: Failed with result 'signal'.
Dec 03 10:25:18 mc01 systemd[1]: minecraft.service: Consumed 20.808s CPU time.
Dec 03 10:25:28 mc01 systemd[1]: minecraft.service: Scheduled restart job, restart counter is at 1.
Dec 03 10:25:28 mc01 systemd[1]: Started minecraft.service - Minecraft server.
NRestarts=1

The restart came exactly 10 seconds after the kill, which is RestartSec=10 at work, and NRestarts=1 counts it. A pass proves systemd restarts the process. It does not prove the world is intact, so check the log for Done after the restart.

What a Crash Does to Unsaved Progress

A crash loses unsaved progress, because auto restart brings the server back but cannot save what Java never wrote.

To measure it, we set the world clock with time set, ended the server two ways and read the clock after the restart with time query time.

World clock before and after each kind of stop
How the server endedClock beforeClock after restartChange kept
SIGTERM, what systemctl stop sends if the console stop fails1802018207Yes
SIGKILL, like a hard crash or out of memory kill602018317No, it went back to the last save

SIGTERM let the vanilla server save, while SIGKILL threw the change away. This was one test with one value, so treat it as a sign of the behaviour, not a promise for every mod or plugin. Backups and the save-all flush in the daily restart below limit what a crash can cost.

Stop a Minecraft Crash Loop

A Minecraft crash loop is a server that fails at every start, and the start limit makes systemd give up after a set number of tries.

We caused a real one by pointing the service at Java 21, which cannot run the 26.3 server jar. Lines are shortened on the right.

bash
journalctl -u minecraft.service --since "-61s" --no-pager | grep -E "systemd\[|UnsupportedClassVersionError"
Output on Ubuntu 24.04.5, middle restarts removed
Dec 03 10:26:38 mc01 java[2489]:         java.lang.UnsupportedClassVersionError: net/minecraft/bundler/Main has been compiled by a more recent version of the Java Runtime (class file version 69.0)
Dec 03 10:26:38 mc01 systemd[1]: minecraft.service: Main process exited, code=exited, status=1/FAILURE
Dec 03 10:26:38 mc01 systemd[1]: minecraft.service: Failed with result 'exit-code'.
Dec 03 10:26:48 mc01 systemd[1]: minecraft.service: Scheduled restart job, restart counter is at 1.
...
Dec 03 10:27:29 mc01 systemd[1]: minecraft.service: Scheduled restart job, restart counter is at 5.
Dec 03 10:27:29 mc01 systemd[1]: minecraft.service: Start request repeated too quickly.
Dec 03 10:27:29 mc01 systemd[1]: minecraft.service: Failed with result 'exit-code'.
Dec 03 10:27:29 mc01 systemd[1]: Failed to start minecraft.service - Minecraft server.

Class file version 69.0 means the jar needs Java 25, and the installed Java only knew up to 65.0, which is Java 21. After the fifth start in 10 minutes systemd stopped trying and marked the service failed.

The 600 second window is deliberate. The systemd defaults are 5 starts in 10 seconds, and with a 10 second restart delay that limit would never trip. Manual starts count toward the limit too, so a few test restarts can use it up.

Recover After the Start Limit

Recover after the start limit by fixing the cause, then clearing the counter, because a plain start is refused until the window passes.

bash
sudo systemctl start minecraft.service
sudo systemctl reset-failed minecraft.service minecraft.socket
sudo systemctl start minecraft.service
systemctl is-active minecraft.service
Output on Ubuntu 24.04.5
Job for minecraft.service failed because the control process exited with error code.
See "systemctl status minecraft.service" and "journalctl -xeu minecraft.service" for details.
active

Slow Down Restarts With Backoff

Backoff slows down restarts by making each one wait longer than the last, which gives a struggling server room before the next try.

Add with sudo systemctl edit minecraft.service
[Service]
RestartSteps=5
RestartMaxDelaySec=5min

systemd spreads the delays between RestartSec and the cap in steps. With RestartSec=10 the observed gaps in our test were about 10, 20, 39 and 78 seconds, growing toward 5 minutes. Real timings can differ slightly with startup time. These two settings arrived in systemd 254, so leave them out on older versions.

Get an Alert When the Server Fails

An alert when the server fails comes from OnFailure=, which starts another unit each time the service fails.

Create the alert unit, then add the OnFailure= line to the [Unit] section of minecraft.service, either in the file itself or with sudo systemctl edit minecraft.service.

bash
sudo nano /etc/systemd/system/minecraft-alert.service
/etc/systemd/system/minecraft-alert.service
[Unit]
Description=Report a failed Minecraft server

[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t minecraft-alert "minecraft.service failed, see journalctl -u minecraft"
Add with sudo systemctl edit minecraft.service
[Unit]
OnFailure=minecraft-alert.service
Journal after a test kill
Dec 03 10:12:56 mc01 systemd[1]: minecraft.service: Failed with result 'signal'.
Dec 03 10:12:56 mc01 systemd[1]: minecraft.service: Triggering OnFailure= dependencies.
Dec 03 10:12:56 mc01 minecraft-alert[1600]: minecraft.service failed, see journalctl -u minecraft

On systemd 255 it fired on every failure, including ones that were then restarted, not only when systemd gave up. That matches the documented default RestartMode=normal, where each automatic restart passes through a failed state. RestartMode=direct skips that state and the OnFailure= trigger with it. logger only writes to the journal, so replace it with a command that reaches you, such as a webhook call or a mail command.

Schedule a Daily Minecraft Restart With Warnings

A daily Minecraft restart with warnings is a systemd timer that runs a script, which warns players, saves the world and restarts.

The Warning Script

The warning script counts down in chat, runs save-all flush, waits until the save is confirmed and then restarts a running server.

bash
sudo nano /usr/local/bin/mc-restart-warn
/usr/local/bin/mc-restart-warn
#!/bin/sh
set -eu
CONSOLE=/run/minecraft.stdin

send() {
    if [ ! -p "$CONSOLE" ]; then
        echo "console pipe $CONSOLE is missing, is minecraft.socket running?" >&2
        exit 1
    fi
    printf '%s\n' "$1" > "$CONSOLE"
}

systemctl is-active --quiet minecraft.service || { echo "minecraft.service is not running, nothing to restart"; exit 0; }

send "say Scheduled restart in 5 minutes"
sleep 240
send "say Scheduled restart in 1 minute"
sleep 50
send "say Scheduled restart in 10 seconds"
sleep 10
CURSOR=$(journalctl -u minecraft.service -n 1 --show-cursor --no-pager -o cat | sed -n 's/^-- cursor: //p')
send "save-all flush"
i=0
until journalctl -u minecraft.service --after-cursor "$CURSOR" -o cat --no-pager | grep -q "Saved the game"; do
    i=$((i + 1))
    if [ "$i" -ge 60 ]; then
        echo "no save confirmation after 60 seconds, scheduled restart cancelled" >&2
        send "say Scheduled restart cancelled"
        exit 1
    fi
    sleep 1
done
systemctl try-restart minecraft.service

The script notes the journal position, then waits up to 60 seconds for a new "Saved the game" line after it, so an older save message cannot count. If no confirmation arrives, something is wrong with the server, so the script cancels the restart, tells players and exits with an error that shows in systemctl status mc-restart.service. We tested that path with a message that never appears, and the service ended failed while the server kept running. That message is the vanilla and Paper 26.3 wording, so check your own log if a mod changes it. try-restart restarts the service only if it is running, so a server you stopped for maintenance stays stopped.

The scheduled restart is not crash recovery. If the service is stopped or has hit its start limit, the script skips the restart, and you recover the server from its logs as shown earlier.

The Timer and Its Service

The timer and its service are two small files, and the timer starts the service of the same name.

bash
sudo nano /etc/systemd/system/mc-restart.service
sudo nano /etc/systemd/system/mc-restart.timer
/etc/systemd/system/mc-restart.service
[Unit]
Description=Daily Minecraft restart with player warnings

[Service]
Type=oneshot
ExecStart=/usr/local/bin/mc-restart-warn
/etc/systemd/system/mc-restart.timer
[Unit]
Description=Run the Minecraft restart every day at 04:00

[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=false

[Install]
WantedBy=timers.target

Persistent=false, the default, skips a restart that was missed while the machine was off, which is what you want for a restart. The time follows the server time zone, so check it with timedatectl. The warnings start at 04:00 and the restart itself follows about 5 minutes later.

Enable and Check the Timer

Enable and check the timer, then confirm the next run time is the one you meant.

bash
sudo chmod 755 /usr/local/bin/mc-restart-warn
sudo systemd-analyze verify /etc/systemd/system/mc-restart.service /etc/systemd/system/mc-restart.timer
sudo systemctl daemon-reload
sudo systemctl enable --now mc-restart.timer
systemctl list-timers mc-restart.timer --no-pager
Output on Ubuntu 24.04.5
NEXT                        LEFT LAST PASSED UNIT             ACTIVATES
Fri 2026-12-04 04:00:00 UTC  18h -         - mc-restart.timer mc-restart.service

Test the Restart Without Waiting

Test the restart without waiting by starting its service by hand and reading the journal.

bash
sudo systemctl start mc-restart.service
journalctl --since "-1min" --no-pager | grep -E "Scheduled restart|Saved the game|Stopping server|Started minecraft"
Output on Ubuntu 24.04.5, waits shortened
Dec 03 11:03:24 mc01 java[3065]: [11:03:24] [Server thread/INFO]: System chat: Saved the game
Dec 03 11:03:26 mc01 java[3065]: [11:03:26] [Server thread/INFO]: [Not Secure] [Server] Scheduled restart in 5 minutes
Dec 03 11:03:30 mc01 java[3065]: [11:03:30] [Server thread/INFO]: [Not Secure] [Server] Scheduled restart in 1 minute
Dec 03 11:03:33 mc01 java[3065]: [11:03:33] [Server thread/INFO]: [Not Secure] [Server] Scheduled restart in 10 seconds
Dec 03 11:03:35 mc01 java[3065]: [11:03:35] [Server thread/INFO]: System chat: Saved the game
Dec 03 11:03:35 mc01 java[3065]: [11:03:35] [Server thread/INFO]: Stopping server
Dec 03 11:03:36 mc01 systemd[1]: Started minecraft.service - Minecraft server.

Auto Restart a Minecraft Server on Windows

To auto restart a Minecraft server on Windows, start it from a batch file that loops back to the java line whenever the server exits.

This is a basic recovery loop, not an equal of the Linux setup above. It has no start limit, no backoff and no separate scheduled restart, and it treats a typed stop like a crash.

start.bat in the server folder
@echo off
cd /d "%~dp0"
:loop
java -Xms2G -Xmx2G -jar server.jar --nogui
echo Server stopped with exit code %errorlevel%. Restarting in 10 seconds, close this window to cancel.
timeout /t 10
goto loop

The loop restarts after every exit, including a typed stop, so close the window during the countdown to stop it for good. It has no crash loop limit, so a server that fails at every start keeps trying every 10 seconds until you close it.

You can run it two ways. Interactively, you double-click start.bat after signing in and keep the console window open to type commands. In the background, a scheduled task starts it at boot with no window, which survives reboots but hides the console. For the background way, create the task from an administrator Command Prompt and change the path to your own folder.

batch
schtasks /create /tn "Minecraft server" /tr "C:\minecraft\start.bat" /sc onstart /ru System /rl HIGHEST

A task running as System has no visible console window, so you cannot type commands into it, and stopping it means ending the task in Task Scheduler. For daily restarts with warnings on Windows, add a restart plugin or a mod such as Auto Restart for Forge and NeoForge, which can stop the server at set times with warnings while the batch loop starts it again.

Auto Restart With a Loop Script on Linux

A loop script on Linux restarts the server after every exit, which suits a shared host where you cannot add systemd services.

bash
nano /opt/minecraft/start.sh
/opt/minecraft/start.sh
#!/bin/sh
cd /opt/minecraft/server || exit 1
while true; do
    java -Xms1G -Xmx1G -jar server.jar --nogui
    echo "Server stopped with exit code $?. Restarting in 10 seconds, press Ctrl+C to cancel."
    sleep 10
done
After a SIGKILL on Ubuntu 24.04.5
Server stopped with exit code 137. Restarting in 10 seconds, press Ctrl+C to cancel.
[10:17:47] [Server thread/INFO]: Done (0.336s)! For help, type "help"

Exit code 137 is 128 plus signal 9, so the loop saw the kill and started the server again. Run the script inside tmux so it keeps going after you log out.

Change the folder and the java line to match your installation, then make the script executable and start it in a new tmux session, which opens the console right away.

bash
chmod 755 /opt/minecraft/start.sh
tmux new -s minecraft /opt/minecraft/start.sh

Press Ctrl+B and then D to detach and leave the server running. Later, get the console back with this command.

bash
tmux attach -t minecraft

Unlike the systemd setup, the loop does not start at boot, has no start limit and restarts after a typed stop as well.

Paper Restart Command and spigot.yml

The Paper restart command runs the restart script set in spigot.yml, and without that script it simply stops the server.

Restart settings in spigot.yml on Paper 26.3
SettingDefaultWhat it does
settings.restart-script./start.shThe script /restart runs to start the next server
settings.restart-on-crashtrueRuns that script when the watchdog detects an unresponsive server, not after other crashes
settings.timeout-time60Seconds without a tick before the watchdog acts
bash
sudo mc-cmd restart
sleep 15
journalctl -u minecraft.service --since "-30s" -o cat --no-pager | grep -E "RestartCommand|Stopping server|Deactivated|Scheduled restart"
Paper 26.3 under systemd with Restart=always
[10:32:16 INFO]: [STDOUT] [org.spigotmc.RestartCommand] Startup script './start.sh' does not exist! Stopping server.
[10:32:16 INFO]: Stopping server
minecraft.service: Deactivated successfully.
minecraft.service: Scheduled restart job, restart counter is at 1.

Under systemd, let systemd be the only thing that starts the server. Leave restart-script pointing at a file that does not exist and use Restart=always, so /restart becomes a clean stop that systemd turns into a restart. A restart script that launches Java itself would start a second copy outside systemd. Paper does not restart a server killed from outside, such as by the kernel out of memory killer, which is why the systemd service is still needed.

Auto Restart With a Game Server Panel

Auto restart with a game server panel uses the panel schedule and crash settings instead of systemd or scripts.

Menu names differ between providers and panel software, so look for a schedule or tasks page and a crash or auto restart setting. A good daily schedule sends say warnings as console commands at set offsets, then a restart power action. Check that the panel restarts the server after a crash on its own, and whether that includes a clean stop.

Example daily restart schedule for a game panel
OrderTaskDelay after the previous task
1Send command say Restarting in 5 minutesNone
2Send command say Restarting in 1 minute4 minutes
3Send command save-all flush50 seconds
4Restart power action10 seconds

Enable the schedule, check the next run time the panel shows and run it once by hand to confirm the warnings and the restart. This example was not tested on a panel, because each provider differs.

Use one supervisor only. A loop script or restart mod that also starts the server inside a panel slot can leave two copies fighting over the same world, so let the panel own starting and stopping.

How Often to Restart a Minecraft Server

How often to restart a Minecraft server has no fixed rule, and once a day at a quiet hour is a common choice.

A restart clears whatever built up inside the running process. It does not fix a plugin that leaks memory or a farm that lags the server, it only resets the clock until the problem returns. If the server needs restarting every few hours, find the cause with a profiler. Paper 26.3 ships with spark, which started on its own in our test log.

For modpacks and busy servers some admins restart twice a day. Each restart disconnects players and costs the startup time, so pick the lowest frequency that keeps your server healthy.

Minecraft Auto Restart Troubleshooting

Minecraft auto restart troubleshooting starts in two places: systemctl status minecraft and journalctl -u minecraft.

Common auto restart problems and fixes
What you seeLikely causeFix
Server does not come back after stopExit code 0 with Restart=on-failureExpected. Use Restart=always if stop should restart it
Start request repeated too quicklyThe start limit was reachedFix the cause in the journal, then systemctl reset-failed minecraft.service minecraft.socket
UnsupportedClassVersionErrorJava is older than the server jar needsInstall the Java version listed for your Minecraft version
FAILED TO BIND TO PORTAnother process holds 25565sudo ss -ltnp 'sport = :25565' shows which one
Failed to open FIFO, File existsSomething wrote to the pipe path while the socket was downDelete the plain file /run/minecraft.stdin, then start the service
Stop takes 60 seconds or moreThe stop came during startup and was rejectedWait for Done before stopping, or let SIGTERM finish it
Daily restart never runsTimer not enabled or a different time zonesystemctl list-timers and timedatectl
Daily restart service failsScript not executable, missing console pipe, no save confirmation or a unit typosystemctl status mc-restart.service and journalctl -u mc-restart.service
Players lose recent builds after a crashHard kill before the last saveNormal for SIGKILL. Keep backups and look for the crash cause

Which Auto Restart Setup to Use

Which auto restart setup to use depends on where the server runs and how much control you have over it.

  • A Linux VPS or dedicated server with root: the systemd service for crashes plus the timer for daily restarts.
  • Linux without root: the loop script in tmux, with a restart plugin or mod for daily restarts.
  • Windows: the batch loop, started by hand or by a scheduled task, with a plugin or mod for daily restarts.
  • A rented game server slot: the panel schedule and crash setting, and nothing else starting the server.

Whatever you pick, keep crash recovery and the scheduled restart as separate pieces, test both once on purpose and keep a recent backup.

Questions people ask

How do I make my Minecraft server restart automatically after a crash?

Set it up as a systemd service and add Restart=on-failure plus RestartSec=10. In our test systemd restarted it 10 seconds after a SIGKILL.

How do I restart a Minecraft server every 24 hours?

Use a systemd timer with OnCalendar=*-*-* 04:00:00 that runs a script to warn players, run save-all flush and restart the service.

Does a Minecraft server restart automatically after /stop?

Not with Restart=on-failure, because /stop exits with code 0. With Restart=always or a loop script it starts again.

How do I auto restart a Paper server?

Run Paper under the same systemd service and use Restart=always. Paper /restart without a start script stops the server and systemd brings it back.

Does auto restart reboot my VPS?

No. It stops and starts only the Java server process. With systemctl enable the service also starts on its own when the VPS boots.

How do I restart a Minecraft server without losing progress?

Run save-all flush and then stop, or use systemctl restart, which sends stop through the console. A clean restart keeps the world, while killing Java can lose recent changes.

Can I auto restart a Minecraft server on Windows?

Yes. Start it from a batch file with a goto loop, and start that file with a Task Scheduler task set to run at startup.

Why does my Minecraft server keep restarting?

It fails at every start, often from a wrong Java version, a taken port or a broken mod. Read journalctl -u minecraft for the first error.

Sources

  1. systemd.service manual, Restart, RestartSec, RestartSteps, ExecStop
  2. systemd.unit manual, StartLimitIntervalSec, StartLimitBurst, OnFailure
  3. systemd-system.conf manual, default start limit values
  4. systemd.timer manual, OnCalendar and Persistent
  5. systemd.socket manual, ListenFIFO and SocketMode
  6. Mojang version data for Minecraft 26.3, Java version
  7. PaperMC documentation, spigot.yml reference
  8. Microsoft Learn, schtasks create
  9. Modrinth, Auto Restart mod for Forge and NeoForge

Written and tested by VPS Lane EngineeringWe run every step on real servers before publishing and update the guide when the software changes.