-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
69 lines (58 loc) · 2.03 KB
/
start.sh
File metadata and controls
69 lines (58 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
echo "Starting multiplayer platformer game container..."
# Detect if running on Render (Render sets RENDER environment variable)
if [ -n "$RENDER" ] || [ -n "$RENDER_EXTERNAL_HOSTNAME" ]; then
echo "🌐 Detected Render.com deployment"
export IS_RENDER=true
# Use Render-optimized nginx config
cp /etc/nginx/nginx-render.conf /etc/nginx/nginx.conf 2>/dev/null || echo "Using default nginx config"
# Set WebSocket URL for Render
export WS_URL="wss://${RENDER_EXTERNAL_HOSTNAME:-$RENDER_EXTERNAL_URL}/ws"
echo "🔗 WebSocket URL: $WS_URL"
else
echo "🐳 Local/Docker deployment"
export IS_RENDER=false
fi
# Start the multiplayer server in background
echo "Starting multiplayer server on port 3001..."
cd /app
PORT=3001 && node server.js &
SERVER_PID=$!
# Wait a moment for server to start
sleep 2
# Check if multiplayer server started successfully
if kill -0 $SERVER_PID 2>/dev/null; then
echo "✓ Multiplayer server started successfully (PID: $SERVER_PID)"
else
echo "⚠ Multiplayer server failed to start, but continuing with game-only mode"
fi
# Start nginx in the foreground
echo "Starting game client on port 80..."
nginx -g "daemon off;" &
NGINX_PID=$!
echo "✓ Game client started successfully"
echo ""
if [ "$IS_RENDER" = "true" ]; then
echo "🎮 Game is available at: https://${RENDER_EXTERNAL_HOSTNAME:-your-app}"
echo "🌐 Multiplayer WebSocket: wss://${RENDER_EXTERNAL_HOSTNAME:-your-app}/ws"
else
echo "🎮 Game is available at: http://localhost:80"
echo "🌐 Multiplayer server at: http://localhost:3001"
fi
echo ""
echo "The game will work in single-player mode even if multiplayer server fails."
# Function to handle shutdown
shutdown() {
echo ""
echo "Shutting down services..."
kill $SERVER_PID 2>/dev/null
kill $NGINX_PID 2>/dev/null
wait $SERVER_PID 2>/dev/null
wait $NGINX_PID 2>/dev/null
echo "Services stopped."
exit 0
}
# Trap signals for graceful shutdown
trap shutdown SIGTERM SIGINT
# Wait for nginx (main process)
wait $NGINX_PID