📘 Minecraft Server Auto-Restart Script with screen on Linux
128 views
📘 Minecraft Server Auto-Restart Script with screen
on Linux
🎥 Video Tutorial Available:
Set up explained step-by-step in this video:
👉 Watch the tutorial on YouTube
📥 Download Available:
Download the script files.
👉 Download here
📁 Folder Structure
server-folder/
├── app.jar # Your Minecraft server JAR file
├── loop.sh # Restart loop script
└── start.sh # Entry point to launch the server in a detached session
📄 Files Overview
1. start.sh
This script checks if screen
and java
are installed, navigates to its own directory, and starts loop.sh
in a detached screen session.
#!/bin/bash
# Check if required commands are available
command -v screen >/dev/null 2>&1 || { echo >&2 "Error: 'screen' is not installed. Aborting."; exit 1; }
command -v java >/dev/null 2>&1 || { echo >&2 "Error: 'java' is not installed. Aborting."; exit 1; }
# Change to the script's directory
BINDIR=$(dirname "$(readlink -fn "$0")")
cd "$BINDIR" || exit 1
# Start the server loop in a detached screen session named 'lobby1'
screen -dmS "lobby1" bash ./loop.sh
2. loop.sh
This script starts your Minecraft server and automatically restarts it if it stops.
#!/bin/bash
BINDIR=$(dirname "$(readlink -fn "$0")")
cd "$BINDIR"
echo -ne "\033]0;lobby1\007" # Set terminal title to 'lobby1'
while true; do
java -Xms1G -Xmx1G -jar app.jar
echo "You want to stop the server? Then press CTRL+C before the counter reaches 1"
echo "Reboot in:"
for i in 5 4 3 2 1; do
echo "$i..."
sleep 1
done
echo "Server rebooting!"
done
Replace
app.jar
with your actual server JAR filename (e.g.,paper-1.20.4.jar
).
▶️ How to Start
-
Make both scripts executable:
chmod +x start.sh loop.sh
-
Start the server:
./start.sh
-
Attach to the screen session (optional):
screen -r lobby1
-
To detach again, press
Ctrl+A
, thenD
.
🧩 Known Issues
❌ screen is terminating
Error
Sometimes, the screen
session crashes immediately with a "terminating" message. This is usually due to misconfigured shell environments or permissions.
✅ Solutions
- Check this SpigotMC forum thread for background: Spigot Forum – screen is terminating
- Solution explained here: unix.stackexchange.com – screen is terminating
💡 Tips
-
To stop the server gracefully, attach to the screen (
screen -r lobby1
) and typestop
in the console. -
To kill the session completely:
screen -S lobby1 -X quit
👨💻 Ente_3
☕ Java
🐟Inocnnu Dev