OrbitMC commited on
Commit
d31504f
·
verified ·
1 Parent(s): 5428e7b

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +62 -51
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
- # --- Environment Variables Check ---
10
- echo ">>> Checking environment variables..."
11
 
12
- # Check if Google Drive URL is configured
13
- if [ -n "$FOLDER_URL" ]; then
14
- echo " Google Drive folder URL is configured"
15
  else
16
- echo "⚠️ FOLDER_URL not set - will create default Minecraft world"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  fi
18
 
19
- # --- Download World Data from Google Drive ---
20
- echo ">>> Attempting to download world data from Google Drive..."
 
 
 
 
 
 
 
 
21
 
22
- # Run the Python script to download and extract world files
23
- # Use the virtual environment Python if we're using that approach
24
- if [ -f "/opt/venv/bin/python3" ]; then
25
- /opt/venv/bin/python3 /app/download_world.py || {
26
- echo "⚠️ World download failed or skipped"
27
- echo ">>> Proceeding with default world generation..."
28
- }
29
  else
30
- python3 /app/download_world.py || {
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
- # --- Check what world folders exist ---
42
- echo ">>> Checking available world folders:"
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 the Minecraft Server ---
57
- echo ">>> Starting Minecraft server..."
58
- echo ">>> If no world folders were found, Minecraft will generate a new world"
 
59
 
60
- # Start the Java Minecraft server with optimized flags
61
- java -Xmx14336M -Xms14336M -XX:+UseG1GC -XX:+ParallelRefProcEnabled \
62
- -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions \
63
- -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=40 \
64
- -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M \
65
- -XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 \
66
- -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=20 \
67
- -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 \
68
- -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 \
 
 
 
 
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