Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -44,18 +44,32 @@ def load_env_vars():
|
|
44 |
'NGROK_TOKEN': ngrok_token
|
45 |
}
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
def check_ngrok():
|
48 |
"""Check if ngrok is available and return the path"""
|
|
|
|
|
49 |
# Check system PATH first
|
50 |
ngrok_path = shutil.which("ngrok")
|
51 |
if ngrok_path:
|
52 |
try:
|
53 |
result = subprocess.run([ngrok_path, "version"], capture_output=True, text=True)
|
54 |
-
print(f"Found ngrok: {ngrok_path}")
|
55 |
print(f"Version: {result.stdout.strip()}")
|
56 |
return ngrok_path
|
57 |
-
except:
|
58 |
-
|
59 |
|
60 |
# Check our custom ngrok installation
|
61 |
custom_ngrok = NGROK_DIR / "ngrok"
|
@@ -65,9 +79,10 @@ def check_ngrok():
|
|
65 |
print(f"Found custom ngrok: {custom_ngrok}")
|
66 |
print(f"Version: {result.stdout.strip()}")
|
67 |
return str(custom_ngrok)
|
68 |
-
except:
|
69 |
-
|
70 |
|
|
|
71 |
return None
|
72 |
|
73 |
def install_ngrok():
|
@@ -105,6 +120,8 @@ def install_ngrok():
|
|
105 |
|
106 |
def setup_ngrok():
|
107 |
"""Setup ngrok with authentication token"""
|
|
|
|
|
108 |
env_vars = load_env_vars()
|
109 |
ngrok_token = env_vars.get('NGROK_TOKEN')
|
110 |
|
@@ -145,12 +162,13 @@ def setup_ngrok():
|
|
145 |
|
146 |
def start_ngrok_tunnel(port=25565):
|
147 |
"""Start ngrok tunnel for the Minecraft server"""
|
|
|
|
|
148 |
ngrok_path = check_ngrok()
|
149 |
if not ngrok_path:
|
150 |
print("ngrok not found. Run setup first.")
|
151 |
-
return None
|
152 |
|
153 |
-
print(f"Starting ngrok tunnel for port {port}...")
|
154 |
try:
|
155 |
# Start ngrok in background
|
156 |
process = subprocess.Popen([
|
@@ -160,9 +178,6 @@ def start_ngrok_tunnel(port=25565):
|
|
160 |
# Give ngrok a moment to start
|
161 |
import time
|
162 |
time.sleep(3)
|
163 |
-
stdout, stderr = process.communicate(timeout=1) # Add timeout to avoid hanging
|
164 |
-
print("STDOUT:", stdout)
|
165 |
-
print("STDERR:", stderr)
|
166 |
|
167 |
# Try to get the tunnel URL from ngrok API
|
168 |
try:
|
@@ -217,16 +232,6 @@ def check_java():
|
|
217 |
pass
|
218 |
|
219 |
return None
|
220 |
-
"""Detect the platform architecture"""
|
221 |
-
import platform
|
222 |
-
machine = platform.machine().lower()
|
223 |
-
if 'x86_64' in machine or 'amd64' in machine:
|
224 |
-
return "linux_x64"
|
225 |
-
elif 'aarch64' in machine or 'arm64' in machine:
|
226 |
-
return "linux_aarch64"
|
227 |
-
else:
|
228 |
-
print(f"Unsupported architecture: {machine}")
|
229 |
-
return "linux_x64" # Default fallback
|
230 |
|
231 |
def download_file(url, destination):
|
232 |
print(f"Downloading {url}...")
|
@@ -417,8 +422,25 @@ def start_server():
|
|
417 |
return False
|
418 |
|
419 |
if __name__ == "__main__":
|
420 |
-
|
421 |
-
|
422 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
423 |
else:
|
424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
'NGROK_TOKEN': ngrok_token
|
45 |
}
|
46 |
|
47 |
+
def get_platform():
|
48 |
+
"""Detect the platform architecture"""
|
49 |
+
import platform
|
50 |
+
machine = platform.machine().lower()
|
51 |
+
if 'x86_64' in machine or 'amd64' in machine:
|
52 |
+
return "linux_x64"
|
53 |
+
elif 'aarch64' in machine or 'arm64' in machine:
|
54 |
+
return "linux_aarch64"
|
55 |
+
else:
|
56 |
+
print(f"Unsupported architecture: {machine}")
|
57 |
+
return "linux_x64" # Default fallback
|
58 |
+
|
59 |
def check_ngrok():
|
60 |
"""Check if ngrok is available and return the path"""
|
61 |
+
print("Checking for ngrok...")
|
62 |
+
|
63 |
# Check system PATH first
|
64 |
ngrok_path = shutil.which("ngrok")
|
65 |
if ngrok_path:
|
66 |
try:
|
67 |
result = subprocess.run([ngrok_path, "version"], capture_output=True, text=True)
|
68 |
+
print(f"Found ngrok in PATH: {ngrok_path}")
|
69 |
print(f"Version: {result.stdout.strip()}")
|
70 |
return ngrok_path
|
71 |
+
except Exception as e:
|
72 |
+
print(f"Error checking system ngrok: {e}")
|
73 |
|
74 |
# Check our custom ngrok installation
|
75 |
custom_ngrok = NGROK_DIR / "ngrok"
|
|
|
79 |
print(f"Found custom ngrok: {custom_ngrok}")
|
80 |
print(f"Version: {result.stdout.strip()}")
|
81 |
return str(custom_ngrok)
|
82 |
+
except Exception as e:
|
83 |
+
print(f"Error checking custom ngrok: {e}")
|
84 |
|
85 |
+
print("ngrok not found")
|
86 |
return None
|
87 |
|
88 |
def install_ngrok():
|
|
|
120 |
|
121 |
def setup_ngrok():
|
122 |
"""Setup ngrok with authentication token"""
|
123 |
+
print("Setting up ngrok...")
|
124 |
+
|
125 |
env_vars = load_env_vars()
|
126 |
ngrok_token = env_vars.get('NGROK_TOKEN')
|
127 |
|
|
|
162 |
|
163 |
def start_ngrok_tunnel(port=25565):
|
164 |
"""Start ngrok tunnel for the Minecraft server"""
|
165 |
+
print(f"Starting ngrok tunnel for port {port}...")
|
166 |
+
|
167 |
ngrok_path = check_ngrok()
|
168 |
if not ngrok_path:
|
169 |
print("ngrok not found. Run setup first.")
|
170 |
+
return None, None
|
171 |
|
|
|
172 |
try:
|
173 |
# Start ngrok in background
|
174 |
process = subprocess.Popen([
|
|
|
178 |
# Give ngrok a moment to start
|
179 |
import time
|
180 |
time.sleep(3)
|
|
|
|
|
|
|
181 |
|
182 |
# Try to get the tunnel URL from ngrok API
|
183 |
try:
|
|
|
232 |
pass
|
233 |
|
234 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
def download_file(url, destination):
|
237 |
print(f"Downloading {url}...")
|
|
|
422 |
return False
|
423 |
|
424 |
if __name__ == "__main__":
|
425 |
+
print("=== Minecraft Server Setup ===")
|
426 |
+
|
427 |
+
# Step 1: Setup Minecraft server
|
428 |
+
if not setup_minecraft_server():
|
429 |
+
print("Setup failed. Cannot start server.")
|
430 |
+
sys.exit(1)
|
431 |
+
|
432 |
+
# Step 2: Setup ngrok
|
433 |
+
print("\n=== Setting up ngrok ===")
|
434 |
+
if not setup_ngrok():
|
435 |
+
print("ngrok setup failed. Server will start but won't be accessible externally.")
|
436 |
+
ngrok_process = None
|
437 |
else:
|
438 |
+
# Step 3: Start ngrok tunnel
|
439 |
+
print("\n=== Starting ngrok tunnel ===")
|
440 |
+
ngrok_process, tunnel_url = start_ngrok_tunnel()
|
441 |
+
if not ngrok_process:
|
442 |
+
print("Failed to start ngrok tunnel. Server will start but won't be accessible externally.")
|
443 |
+
|
444 |
+
# Step 4: Start the server
|
445 |
+
print("\n=== Starting Minecraft Server ===")
|
446 |
+
start_server()
|