Server / start.sh
OrbitMC's picture
Update start.sh
4559db5 verified
#!/bin/bash
set -e
echo "==== Server Initialization ===="
# --- Start background service ---
echo ">> Configuring network connectivity..."
if [ -z "$PLAYIT_SECRET" ]; then
echo "⚠️ Network configuration not set"
echo " Add configuration in Space Settings -> Secrets"
else
echo "✅ Network config detected"
PLAYIT_CMD=$(which playit || echo "/usr/bin/playit")
if [ -f "$PLAYIT_CMD" ]; then
echo "✅ Starting network service"
$PLAYIT_CMD --secret "$PLAYIT_SECRET" > /dev/null 2>&1 &
PLAYIT_PID=$!
sleep 5
if ps -p $PLAYIT_PID >/dev/null 2>&1; then
echo "✅ Network service active"
else
echo "⚠️ Service not running"
fi
else
echo "⚠️ Network tools unavailable"
fi
fi
# --- Server Configuration ---
echo ">> Setting up server environment..."
if [ -f "server.properties" ]; then
sed -i "s/^server-port=.*/server-port=7860/" server.properties
sed -i "s/^query.port=.*/query.port=7860/" server.properties
echo "✅ Port configured: 7860"
else
echo "⚠️ Using default configuration"
fi
# --- Data Setup ---
echo ">> Loading world data..."
if command -v python3 >/dev/null 2>&1 && [ -f "download_world.py" ]; then
python3 download_world.py || echo "⚠️ Using default world"
else
echo "ℹ️ No custom data found"
fi
chmod -R 777 /app/world* 2>/dev/null || true
chmod -R 777 /app/plugins 2>/dev/null || true
echo "Available data folders:"
ls -la /app/ | grep world || echo "No custom data - generating new"
# --- Start Main Service ---
echo ">> Starting main service on port 7860..."
echo ">> Java: $(java -version 2>&1 | head -n 1)"
echo ">> Memory: 8GB allocated"
exec java -server -Xmx8G -Xms8G \
-XX:+UseG1GC \
-XX:+ParallelRefProcEnabled \
-XX:MaxGCPauseMillis=50 \
-XX:+UnlockExperimentalVMOptions \
-XX:+DisableExplicitGC \
-XX:+AlwaysPreTouch \
-XX:G1NewSizePercent=20 \
-XX:G1MaxNewSizePercent=40 \
-XX:G1HeapRegionSize=8M \
-XX:G1ReservePercent=10 \
-XX:G1HeapWastePercent=5 \
-XX:G1MixedGCCountTarget=4 \
-XX:InitiatingHeapOccupancyPercent=15 \
-XX:G1MixedGCLiveThresholdPercent=85 \
-XX:G1RSetUpdatingPauseTimePercent=5 \
-XX:SurvivorRatio=32 \
-XX:+PerfDisableSharedMem \
-XX:MaxTenuringThreshold=1 \
-jar purpur.jar --nogui