Skip to main content
← All Guides
Server Admin · 5 min read

How to Auto-Restart Your Minecraft Server (systemd, screen, tmux)

Set up automatic restarts for your Minecraft server using systemd, screen, or tmux. Covers crash recovery, scheduled restarts, and watchdog scripts.

Why Auto-Restart Matters

Minecraft servers crash. Memory leaks build up, plugins throw unhandled exceptions, and sometimes the JVM itself hits a fatal error. Without an auto restart minecraft server setup, your community sits on a dead server until you notice and manually bring it back online, which might be hours if it happens at 3 AM. An automatic restart mechanism detects the crash and brings the server back within seconds, keeping downtime to an absolute minimum.

Beyond crash recovery, scheduled restarts clear memory fragmentation, reload configs, and keep TPS stable during long uptimes. Most well-run servers restart once every 6-12 hours on a predictable schedule. This guide covers three methods to auto restart your minecraft server: systemd (the cleanest), screen with a wrapper script, and tmux with a watchdog loop.

Method 1: systemd (Recommended)

If you are running your server on a modern Linux distribution, and you should be, per our headless Linux guide, systemd is the best way to handle auto restarts. Create a dedicated system user first:

sudo useradd -r -m -d /opt/minecraft minecraft
sudo chown -R minecraft:minecraft /opt/minecraft

Create the service file at /etc/systemd/system/minecraft.service:

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

[Service]
User=minecraft
WorkingDirectory=/opt/minecraft
ExecStart=/usr/bin/java -Xms4G -Xmx4G -jar server.jar --nogui
Restart=always
RestartSec=15
SuccessExitStatus=0 143

[Install]
WantedBy=multi-user.target

The key directives for auto restart minecraft server behavior:

  • Restart=always, restart regardless of how the process exited (crash, OOM kill, manual stop via the stop command). Use Restart=on-failure if you want /stop to actually stop the server without restarting.
  • RestartSec=15, wait 15 seconds before restarting to allow file locks to release and ports to unbind.
  • SuccessExitStatus=0 143, treat exit code 143 (SIGTERM) as a clean exit so systemd does not log it as a failure.

Enable and start:

sudo systemctl daemon-reload
sudo systemctl enable minecraft
sudo systemctl start minecraft

View live logs with journalctl -u minecraft -f. The server will now auto restart after any crash and start automatically on boot.

Sending Console Commands to a systemd Service

One downside of a plain systemd setup is that you lose interactive console access. Solve this by wrapping the server in a screen or tmux session inside the service:

ExecStart=/usr/bin/screen -DmS mc /usr/bin/java -Xms4G -Xmx4G -jar server.jar --nogui
ExecStop=/usr/bin/screen -S mc -X stuff "stop$(printf '\r')"

Now you can attach with sudo -u minecraft screen -r mc and send commands from cron jobs.

Method 2: screen Wrapper Script

If you cannot or do not want to use systemd, a simple bash loop inside screen achieves the same crash-recovery behavior:

#!/bin/bash
# start.sh, auto-restarting Minecraft server
cd /opt/minecraft

while true; do
  echo "[$(date)] Starting server..."
  java -Xms4G -Xmx4G -jar server.jar --nogui
  EXIT_CODE=$?
  echo "[$(date)] Server exited with code $EXIT_CODE"

  if [ -f .stop ]; then
    echo "Stop file detected. Not restarting."
    rm .stop
    break
  fi

  echo "Restarting in 10 seconds..."
  sleep 10
done

Launch it inside a screen session:

screen -S minecraft bash start.sh

To stop the server permanently without it restarting, create a stop file before issuing the stop command:

touch /opt/minecraft/.stop
screen -S minecraft -X stuff "stop$(printf '\r')"

This approach is portable and works on any system, but it does not survive reboots unless you add the screen command to /etc/rc.local or a cron @reboot entry.

Method 3: tmux Watchdog

The tmux equivalent works identically but uses tmux session management:

#!/bin/bash
# start-tmux.sh
cd /opt/minecraft

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

  if [ -f .stop ]; then
    rm .stop
    break
  fi

  echo "Restarting in 10 seconds..."
  sleep 10
done
tmux new-session -d -s minecraft "bash /opt/minecraft/start-tmux.sh"

Send commands to the running server:

tmux send-keys -t minecraft "say Restarting in 1 minute" Enter

Scheduled Restarts with Graceful Warnings

Combine any auto restart minecraft server method with cron or systemd timers for scheduled restarts. Here is a cron job that warns players and restarts every 6 hours:

# /opt/minecraft/restart.sh
#!/bin/bash
SESSION="minecraft"
tmux send-keys -t $SESSION "say Server restarting in 60 seconds. Save your progress!" Enter
sleep 30
tmux send-keys -t $SESSION "say Server restarting in 30 seconds..." Enter
sleep 20
tmux send-keys -t $SESSION "say Restarting in 10 seconds!" Enter
sleep 10
tmux send-keys -t $SESSION "stop" Enter
# crontab -e
0 */6 * * * /opt/minecraft/restart.sh

The wrapper script or systemd will catch the exit and bring the server back up automatically. For more advanced scheduling including plugin-based task automation, see our scheduling guide.

Monitoring and Alerts

An auto restart setup is only useful if you know it happened. Check systemd restart history with:

systemctl show minecraft --property=NRestarts

For notifications, add an ExecStartPre line to your systemd unit that sends a webhook to Discord or posts to a monitoring service. You can also use Spark to monitor TPS and detect degradation before a crash happens.

Summary

The easiest and most reliable way to auto restart your minecraft server is systemd with Restart=always. If you need interactive console access, wrap the Java process in screen or tmux inside the systemd unit. For servers not running systemd, a bash while-loop inside screen or tmux achieves the same result. Always pair crash recovery with scheduled restarts and make sure you have automated backups running independently.

Want managed hosting instead? Astroworld Hosting handles auto-restarts, updates, and backups for you.

Related Tools & Resources

🔧

Minecraft Tools

Calculators, generators & server tools

🧱

Item Database

Browse all Minecraft items, stats & recipes

⚒️

Crafting Recipes

Visual crafting guides for every recipe