---
title: "Setting Up Automatic Restarts and Crash Recovery | ZCS"
description: "A server that crashes at 3 AM and stays down until someone notices costs more uptime than almost any other single failure."
url: "https://www.zcraftstudios.com/blog/minecraft-server-auto-restart-crash-recovery"
updated: "2026-10-20T07:15:13.005688+00:00"
source: "ZCraft Studios"
---

> Site index for AI agents: https://www.zcraftstudios.com/llms.txt (full reference: https://www.zcraftstudios.com/llms-full.txt). Every page is available as Markdown by adding `.md` to its URL or sending `Accept: text/markdown`.

1. [Home](https://www.zcraftstudios.com/)
2. [Blog](https://www.zcraftstudios.com/blog)
3. Setting Up Automatic Restarts and Crash Recovery

[ All posts](https://www.zcraftstudios.com/blog)

# Setting Up Automatic Restarts and Crash Recovery

ZCraft StudiosOct 3, 2026Updated Oct 20, 2026

A server that crashes at 3 AM and stays down until someone notices costs more uptime than almost any other single failure.

## In this guide

- [A Basic Auto-Restart Loop](#a-basic-auto-restart-loop)
- [Distinguishing a Crash From an Intentional Stop](#distinguishing-a-crash-from-an-intentional-stop)
- [Running It as a systemd Service (Linux)](#running-it-as-a-systemd-service-linux)
- [Scheduled Restarts (Not Just Crash Recovery)](#scheduled-restarts-not-just-crash-recovery)
- [Monitoring, Not Just Recovering](#monitoring-not-just-recovering)
- [Distinguish planned restarts from crash loops](#distinguish-planned-restarts-from-crash-loops)
- [Official documentation and links](#official-documentation-and-links)
- [Distinguish a crash from a restart loop](#distinguish-a-crash-from-a-restart-loop)

## Setting Up Automatic Restarts and Crash Recovery

_The server crashing is inevitable eventually. Staying down for six hours because nobody was awake to restart it is the part that's actually preventable._

A simple restart loop around the server's start command means a crash results in a few seconds of downtime instead of however long until someone notices and manually restarts it.

## A Basic Auto-Restart Loop

Instead of running the server's start command directly, wrap it in a loop that restarts it whenever the process exits:

```
#!/bin/bash
cd /home/mc/myserver

while true; do
    java -Xms4G -Xmx4G -jar paper.jar nogui
    echo "Server stopped — restarting in 5 seconds..."
    sleep 5
done
```

Save this as `start-loop.sh`, make it executable (`chmod +x start-loop.sh`), and run it inside a `screen` or `tmux` session so it keeps running after disconnecting.

## Distinguishing a Crash From an Intentional Stop

The loop above restarts on **any** exit, including an intentional `/stop` from an admin, which usually isn't what's wanted. A common fix is checking for a "stop file" the restart script respects:

```
#!/bin/bash
cd /home/mc/myserver
rm -f ./.stop-requested

while true; do
    java -Xms4G -Xmx4G -jar paper.jar nogui

    if [ -f "./.stop-requested" ]; then
        echo "Intentional stop detected — not restarting."
        break
    fi

    echo "Unexpected exit — restarting in 5 seconds..."
    sleep 5
done
```

An admin creates `.stop-requested` (via a plugin, or manually) before running `/stop`, and the loop respects it instead of restarting.

## Running It as a systemd Service (Linux)

For a more robust setup than a manual `screen` session, a systemd service handles both auto-restart and starting on boot:

```
[Unit]
Description=Minecraft Server
After=network.target

[Service]
WorkingDirectory=/home/mc/myserver
ExecStart=/usr/bin/java -Xms4G -Xmx4G -jar paper.jar nogui
Restart=on-failure
RestartSec=5
User=mc

[Install]
WantedBy=multi-user.target
```

Save as `/etc/systemd/system/minecraft.service`, then:

```
sudo systemctl enable minecraft
sudo systemctl start minecraft
```

`Restart=on-failure` handles the crash-vs-intentional-stop distinction automatically: a clean `/stop` exits with a success code and isn't restarted, while a crash exits with a failure code and is.

## Scheduled Restarts (Not Just Crash Recovery)

Many servers also restart on a schedule (daily or every few hours) regardless of crashes, to clear accumulated memory fragmentation and apply any pending plugin updates. A cron job sending a graceful `/stop` (with a warning broadcast beforehand) at a fixed time, combined with either of the methods above, covers both scheduled and crash-driven restarts with one setup.

## Monitoring, Not Just Recovering

An auto-restart loop solves downtime duration but not downtime visibility. A logging line, a webhook to Discord on each unexpected restart, or basic uptime monitoring (even a simple external ping check) means repeated crashes actually get noticed and investigated instead of silently restarting forever.

## Distinguish planned restarts from crash loops

A healthy restart is a controlled shutdown followed by a new start. A crash-recovery loop is different: the server may exit immediately over and over because a required file is missing or a plugin cannot load. An aggressive restart policy can hide the original problem and repeatedly stress the machine.

### A safer operating procedure

1. Save and back up the world before maintenance.
2. Announce a planned restart to connected players.
3. Stop the server gracefully and confirm the process exited.
4. Restart through the host's process manager.
5. Check the console for successful world and plugin initialization.
6. Join as a normal player and test essential commands.

For crash recovery, configure the process manager to log exit codes and limit repeated failures. After several rapid crashes, stop automatic retries and investigate the earliest meaningful error in the logs.

**Test scenario:** introduce a harmless startup configuration error on a disposable staging server and confirm you can identify the failed start without losing logs. Never test crash handling by disrupting production.

### What not to assume

Automatic restart does not replace backups, resolve memory leaks, or protect against corrupted data. Record crash frequency and investigate recurring patterns instead of treating restarts as the fix.

## Official documentation and links

- [Official project repository](https://github.com/itzg/docker-minecraft-server)
- [Taking a Minecraft Server Down for Maintenance Without Losing Players](https://www.zcraftstudios.com/blog/minecraft-server-maintenance-mode-without-losing-players)

## Distinguish a crash from a restart loop

A service manager can bring a process back online, but it cannot fix a broken plugin or corrupted file. Set reasonable restart delays and inspect the prior crash log before increasing restart frequency. Alert staff if several restarts occur in a short window.

Schedule clean restarts separately from crash recovery, and ensure a backup or snapshot process does not silently coincide with a forced shutdown.

### Related troubleshooting

- [How to read Minecraft crash reports](https://www.zcraftstudios.com/blog/minecraft-server-crash-report-guide): Crash report interpretation.

## Continue reading

- [Build a LifeSteal Server: Lives, PvP Rules, Recovery](https://www.zcraftstudios.com/blog/minecraft-lifesteal-server-rules-guide)
- [Minecraft Discord Account Linking: Security and Recovery](https://www.zcraftstudios.com/blog/minecraft-server-discord-linking-security)
- [Read Minecraft Crash Reports and Find the Bad Plugin](https://www.zcraftstudios.com/blog/minecraft-server-crash-report-guide)

[ Previous guide Setting Up Skript: Custom Mechanics Without Writing a Plugin](https://www.zcraftstudios.com/blog/skript-custom-mechanics-without-java)[ Next guide Hardening a Minecraft Server With a Firewall](https://www.zcraftstudios.com/blog/minecraft-server-firewall-hardening)
