AutoRestart: Keep Your Minecraft Server Alive on Linux

How to Set Up Auto-Restart for Your Minecraft Linux Server Running a Minecraft server on Linux is a fantastic way to enjoy complete control over your blocky world, but unexpected crashes can bring the fun to a halt. Whether you are hosting a vanilla survival server, a heavily modded Spigot setup,...

Download ShellScripts for Minecraft 1.7.6

Original name: ShellScripts

Minecraft: 1.7.6

FileVersionLoaderSize
ShellScripts.zip1.7.6—1 КБDownload

How to Set Up Auto-Restart for Your Minecraft Linux Server

Running a Minecraft server on Linux is a fantastic way to enjoy complete control over your blocky world, but unexpected crashes can bring the fun to a halt. Whether you are hosting a vanilla survival server, a heavily modded Spigot setup, or a custom Bukkit experience, downtime is the enemy of player engagement. The solution is a simple yet powerful auto-restart system that uses two lightweight shell scripts, the Screen utility, and a cron job. This guide walks you through the entire process, from installing the necessary tools to fine-tuning the restart interval, so your server bounces back automatically without any manual intervention.

Why Auto-Restart Matters

Minecraft servers, especially those running mods or plugins, can occasionally crash due to memory leaks, chunk generation errors, or incompatible mods. Without an automated restart, your players are left staring at a connection refused screen until you manually intervene. By setting up a watchdog script that checks the server process every few seconds, you ensure that downtime is measured in moments rather than hours. The method described here works with any Minecraft server edition—Vanilla, Bukkit, Spigot, Tekkit, and more—because it monitors the Java process itself, not the server software.

Prerequisites: Screen and Basic Linux Knowledge

Before diving into the scripts, you need a Linux server (or a desktop Linux environment) with terminal access. The core tool we will use is screen, a terminal multiplexer that allows you to run the Minecraft server in a background session. This keeps the server alive even after you disconnect from SSH. Most distributions include Screen in their repositories, but we will verify and install it if necessary.

Step-by-Step Guide to Auto-Restart

1. Installing Screen

Open your terminal via SSH or directly on the machine. First, check if Screen is already present by running which screen. If a path like /usr/bin/screen appears, you are good to go. If not, install it with your package manager:

  • On Ubuntu or Debian: sudo apt-get update then sudo apt-get install screen
  • On CentOS or RHEL: yum install screen

Once installed, you can create a new screen session anytime by typing screen -S minecraft.

2. Downloading and Configuring the Scripts

Two essential shell scripts drive the auto-restart mechanism: start.sh and MCServerResetCheck.sh. Place both files in your Minecraft working directory—the same folder that contains your server JAR file (for example, /root/minecraft/). The start.sh script launches the server inside a screen session with your chosen Java parameters. The MCServerResetCheck.sh script periodically checks whether that screen session is still alive; if not, it calls start.sh to bring the server back up.

3. Editing the Scripts with Vi

Open each script using the vi editor. For the check script, run vi MCServerResetCheck.sh. You need to modify the line that defines the working directory path to match your setup. For instance, change MCDIR="/root/minecraft" to your actual folder. You can also rename the log file from MCServerRestartLog.txt to anything you prefer. Press ESC, then type :wq to save and exit.

Next, edit start.sh with vi start.sh. Here, adjust the Java launch command to reflect your server JAR name and memory allocation. A typical line looks like java -Xmx1g -Xms1g -jar spigot-1.11.2.jar. Replace the JAR filename and memory flags as needed. Save the file the same way.

4. Setting Up the Cron Job

Now we tell the system to run the check script at regular intervals using cron. Stop the cron service temporarily with service cron stop (or systemctl stop cron on newer systems), then edit your crontab by typing crontab -e. Add these two lines to make the check run every 30 seconds:

  • * * * * * /root/minecraft/MCServerResetCheck.sh
  • * * * * * ( sleep 30 ; /root/minecraft/MCServerResetCheck.sh )

The first line triggers at the top of every minute, and the second waits 30 seconds before running, effectively creating a 30-second cycle. If you prefer a less frequent check, you can remove one line to run once per minute, or adjust the asterisks—for example, */2 * * * * for every two minutes, up to */59 for every 59 minutes.

5. Testing and Accessing the Server Console

Restart the cron service with service cron start. Your Minecraft server should now start automatically if it is not already running. To verify, use screen -r to resume the screen session and see the server console. To detach without stopping the server, press CTRL + a then d. If the server crashes, the check script will detect the missing screen session and relaunch it within 30 seconds.

Fine-Tuning the Restart Interval

The 30-second interval is lightweight and rarely impacts CPU performance, but you might want a longer gap for heavily modded servers that take time to shut down gracefully. Simply modify the crontab entries as described. While cron-based auto-restart is robust, managing mods and server configurations can still be tedious. For a more streamlined experience, consider using the foxygame.net launcher, a modern Minecraft launcher that lets you download mods directly from the menu, making it easy to keep your server up-to-date without manual file editing. This can complement your automated restart setup, especially if you frequently switch between modpacks.

Conclusion

With just two scripts, Screen, and a cron job, you have built a resilient auto-restart system that keeps your Minecraft Linux server online around the clock. This method is distribution-agnostic and works with any server type, giving you peace of mind whether you are running a small private world or a bustling public network. Once configured, you can forget about manual restarts and focus on what truly matters—exploring new biomes, crafting epic builds, and enjoying the game with your community.