Update start.sh
Browse files
start.sh
CHANGED
|
@@ -1,70 +1,81 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
|
| 3 |
-
# A shell script to set up the environment and run the Minecraft server.
|
| 4 |
-
# Set the script to exit immediately if any command fails.
|
| 5 |
set -e
|
| 6 |
|
| 7 |
-
echo "===== Server Startup at $(date) ====="
|
| 8 |
|
| 9 |
-
# ---
|
| 10 |
-
echo ">>>
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
echo "
|
| 15 |
else
|
| 16 |
-
echo "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
fi
|
| 18 |
|
| 19 |
-
# ---
|
| 20 |
-
echo ">>>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
-
if [ -f "
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
echo ">>> Proceeding with default world generation..."
|
| 28 |
-
}
|
| 29 |
else
|
| 30 |
-
|
| 31 |
-
echo "⚠️ World download failed or skipped"
|
| 32 |
-
echo ">>> Proceeding with default world generation..."
|
| 33 |
-
}
|
| 34 |
fi
|
| 35 |
|
| 36 |
-
# --- Set proper permissions ---
|
| 37 |
-
echo ">>> Setting permissions for world folders..."
|
| 38 |
chmod -R 777 /app/world* 2>/dev/null || true
|
| 39 |
chmod -R 777 /app/plugins 2>/dev/null || true
|
| 40 |
|
| 41 |
-
|
| 42 |
-
echo "
|
| 43 |
-
if [ -d "/app/world" ]; then
|
| 44 |
-
echo "✅ Found: world"
|
| 45 |
-
fi
|
| 46 |
-
if [ -d "/app/world_nether" ]; then
|
| 47 |
-
echo "✅ Found: world_nether"
|
| 48 |
-
fi
|
| 49 |
-
if [ -d "/app/world_the_end" ]; then
|
| 50 |
-
echo "✅ Found: world_the_end"
|
| 51 |
-
fi
|
| 52 |
-
if [ -d "/app/plugins" ]; then
|
| 53 |
-
echo "✅ Found: plugins"
|
| 54 |
-
fi
|
| 55 |
|
| 56 |
-
# --- Start
|
| 57 |
-
echo ">>> Starting Minecraft server..."
|
| 58 |
-
echo ">>>
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
-XX:MaxGCPauseMillis=
|
| 63 |
-
-XX:+DisableExplicitGC -XX:+AlwaysPreTouch
|
| 64 |
-
-XX:
|
| 65 |
-
-XX:
|
| 66 |
-
-XX:
|
| 67 |
-
-XX:
|
| 68 |
-
-XX:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
-Daikars.new.flags=true -Dusing.aikars.flags=https://mcflags.emc.gs \
|
| 70 |
-jar purpur.jar --nogui
|
|
|
|
| 1 |
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
echo "===== Minecraft Server Startup at $(date) ====="
|
| 5 |
|
| 6 |
+
# --- Start Playit.gg with token from Hugging Face secret ---
|
| 7 |
+
echo ">>> Starting Playit.gg tunnel using secret from environment..."
|
| 8 |
|
| 9 |
+
if [ -z "$PLAYIT_SECRET" ]; then
|
| 10 |
+
echo "❌ PLAYIT_SECRET is not set! Please set it in Hugging Face Space Secrets."
|
| 11 |
+
echo " Example: huggingface-cli space secret set PLAYIT_SECRET your_secret_here"
|
| 12 |
else
|
| 13 |
+
echo "✅ PLAYIT_SECRET detected - starting Playit.gg"
|
| 14 |
+
PLAYIT_CMD=$(which playit || echo "/usr/bin/playit")
|
| 15 |
+
|
| 16 |
+
if [ -f "$PLAYIT_CMD" ]; then
|
| 17 |
+
echo "✅ Found playit at: $PLAYIT_CMD"
|
| 18 |
+
$PLAYIT_CMD --secret "$PLAYIT_SECRET" &
|
| 19 |
+
PLAYIT_PID=$!
|
| 20 |
+
sleep 8
|
| 21 |
+
|
| 22 |
+
if ps -p $PLAYIT_PID >/dev/null 2>&1; then
|
| 23 |
+
echo "✅ Playit.gg started successfully with your token!"
|
| 24 |
+
echo "📋 Tunnel is being established..."
|
| 25 |
+
echo "💡 Check your Playit.gg dashboard for connection details"
|
| 26 |
+
else
|
| 27 |
+
echo "⚠️ Playit.gg process not running - may have failed to start"
|
| 28 |
+
echo "ℹ️ Continuing without tunnel - server will still start on port 7860"
|
| 29 |
+
fi
|
| 30 |
+
else
|
| 31 |
+
echo "⚠️ Playit.gg not found at $PLAYIT_CMD"
|
| 32 |
+
echo "ℹ️ Continuing without tunnel - server will still start on port 7860"
|
| 33 |
+
fi
|
| 34 |
fi
|
| 35 |
|
| 36 |
+
# --- Minecraft Server Configuration ---
|
| 37 |
+
echo ">>> Configuring Minecraft server on port 7860..."
|
| 38 |
+
|
| 39 |
+
if [ -f "server.properties" ]; then
|
| 40 |
+
sed -i "s/^server-port=.*/server-port=7860/" server.properties
|
| 41 |
+
sed -i "s/^query.port=.*/query.port=7860/" server.properties
|
| 42 |
+
echo "✅ Server configured for port 7860"
|
| 43 |
+
else
|
| 44 |
+
echo "⚠️ server.properties not found - using default config"
|
| 45 |
+
fi
|
| 46 |
|
| 47 |
+
# --- World Data Setup ---
|
| 48 |
+
echo ">>> Setting up world data..."
|
| 49 |
+
if command -v python3 >/dev/null 2>&1 && [ -f "download_world.py" ]; then
|
| 50 |
+
echo "Attempting to download world data..."
|
| 51 |
+
python3 download_world.py || echo "⚠️ World download failed - using default world"
|
|
|
|
|
|
|
| 52 |
else
|
| 53 |
+
echo "ℹ️ No world download setup found"
|
|
|
|
|
|
|
|
|
|
| 54 |
fi
|
| 55 |
|
|
|
|
|
|
|
| 56 |
chmod -R 777 /app/world* 2>/dev/null || true
|
| 57 |
chmod -R 777 /app/plugins 2>/dev/null || true
|
| 58 |
|
| 59 |
+
echo "Available world folders:"
|
| 60 |
+
ls -la /app/ | grep world || echo "No world folders found - will generate new world"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# --- Start Minecraft Server ---
|
| 63 |
+
echo ">>> Starting Minecraft server on port 7860..."
|
| 64 |
+
echo ">>> Java version: $(java -version 2>&1 | head -n 1)"
|
| 65 |
+
echo ">>> Memory: 8GB allocated"
|
| 66 |
|
| 67 |
+
exec java -Xmx8G -Xms8G \
|
| 68 |
+
-XX:+UseG1GC -XX:+ParallelRefProcEnabled \
|
| 69 |
+
-XX:MaxGCPauseMillis=100 -XX:+UnlockExperimentalVMOptions \
|
| 70 |
+
-XX:+DisableExplicitGC -XX:+AlwaysPreTouch \
|
| 71 |
+
-XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 \
|
| 72 |
+
-XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 \
|
| 73 |
+
-XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 \
|
| 74 |
+
-XX:InitiatingHeapOccupancyPercent=15 \
|
| 75 |
+
-XX:G1MixedGCLiveThresholdPercent=85 \
|
| 76 |
+
-XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 \
|
| 77 |
+
-XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 \
|
| 78 |
+
-XX:ParallelGCThreads=2 -XX:ConcGCThreads=2 \
|
| 79 |
+
-XX:ActiveProcessorCount=2 \
|
| 80 |
-Daikars.new.flags=true -Dusing.aikars.flags=https://mcflags.emc.gs \
|
| 81 |
-jar purpur.jar --nogui
|