This repository was archived by the owner on Apr 11, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrailway-start.sh
More file actions
executable file
·235 lines (196 loc) · 6.38 KB
/
Copy pathrailway-start.sh
File metadata and controls
executable file
·235 lines (196 loc) · 6.38 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/sh
echo "Starting Pterodactyl Panel on Railway..."
PORT=${PORT:-8080}
echo "Using port: $PORT"
if [ ! -f .env ]; then
echo "Creating .env file..."
cp .env.example .env
fi
mkdir -p storage/logs storage/framework/sessions storage/framework/views storage/framework/cache/data bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
chmod -R 777 storage bootstrap/cache
if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "" ]; then
echo "ERROR: APP_KEY is not set in Railway environment variables!"
echo "Please set APP_KEY in Railway dashboard to avoid session/encryption issues"
echo "Generate one with: php artisan key:generate --show"
exit 1
else
echo "Using APP_KEY from environment"
fi
export CACHE_DRIVER=array
export SESSION_DRIVER=file
export LOG_CHANNEL=stderr
export LOG_LEVEL=debug
export APP_DEBUG=true
echo "Running migrations..."
php artisan migrate --force --no-interaction 2>&1 || echo "Migration failed, continuing anyway..."
echo "Clearing caches..."
php artisan config:clear 2>/dev/null || true
php artisan cache:clear 2>/dev/null || true
php artisan view:clear 2>/dev/null || true
php artisan route:clear 2>/dev/null || true
rm -rf bootstrap/cache/*.php 2>/dev/null || true
echo "Setting up nginx..."
mkdir -p /tmp/nginx/fastcgi /tmp/nginx/proxy /tmp/nginx/client_body /tmp/nginx/uwsgi /tmp/nginx/scgi
chown -R nobody:nobody /tmp/nginx
cat > /etc/nginx/nginx.conf << EOF
user nobody;
worker_processes auto;
pid /tmp/nginx.pid;
error_log /dev/stderr info;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout combined;
error_log /dev/stderr warn;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 100M;
fastcgi_temp_path /tmp/nginx/fastcgi;
proxy_temp_path /tmp/nginx/proxy;
client_body_temp_path /tmp/nginx/client_body;
uwsgi_temp_path /tmp/nginx/uwsgi;
scgi_temp_path /tmp/nginx/scgi;
map \$http_upgrade \$connection_upgrade {
default upgrade;
'' close;
}
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
server {
listen $PORT;
server_name _;
root /app/public;
index index.php;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param HTTP_PROXY "";
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location /ws {
proxy_pass http://127.0.0.1:8090;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_read_timeout 86400;
proxy_send_timeout 86400;
proxy_buffering off;
proxy_cache off;
}
location ~ /\.ht {
deny all;
}
}
}
EOF
echo "Setting up PHP-FPM..."
cat > /tmp/php-fpm.conf << 'EOF'
[global]
pid = /tmp/php-fpm.pid
error_log = /dev/stderr
daemonize = no
[www]
user = nobody
group = nobody
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 50
pm.max_requests = 1000
request_terminate_timeout = 60
clear_env = no
catch_workers_output = yes
php_admin_value[error_log] = /dev/stderr
php_admin_flag[log_errors] = on
php_admin_value[display_errors] = on
php_admin_value[display_startup_errors] = on
EOF
echo "Starting PHP-FPM..."
php-fpm -F -y /tmp/php-fpm.conf &
PHP_FPM_PID=$!
echo "Waiting for PHP-FPM to start..."
sleep 3
echo "Testing PHP-FPM connection..."
for i in 1 2 3 4 5; do
if nc -z 127.0.0.1 9000 2>/dev/null; then
echo "PHP-FPM is running on 127.0.0.1:9000"
break
fi
echo "Waiting for PHP-FPM... ($i/5)"
sleep 1
done
echo "Creating health check..."
cat > /app/public/health.php << 'HEALTHEOF'
<?php
echo "OK - PHP-FPM is working\n";
echo "Time: " . date('Y-m-d H:i:s') . "\n";
phpinfo(INFO_GENERAL);
HEALTHEOF
echo "Starting nginx on port $PORT..."
nginx -c /etc/nginx/nginx.conf -g 'daemon off;' &
NGINX_PID=$!
echo "Services started. PHP-FPM PID: $PHP_FPM_PID, Nginx PID: $NGINX_PID"
echo "Health check available at: /health.php"
echo "Testing Laravel..."
sleep 2
curl -s http://127.0.0.1:$PORT/health.php || echo "Health check failed"
RESPONSE=$(curl -s -w "\n%{http_code}" http://127.0.0.1:$PORT/)
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
BODY=$(echo "$RESPONSE" | head -n-1)
if [ "$HTTP_CODE" = "500" ]; then
echo "Laravel returning 500 error"
echo "Checking logs..."
if [ -f storage/logs/laravel-$(date +%Y-%m-%d).log ]; then
echo "=== Laravel Error Log ==="
tail -100 storage/logs/laravel-$(date +%Y-%m-%d).log
fi
else
echo "HTTP $HTTP_CODE"
echo "$BODY" | head -20
fi
echo ""
echo "=== Application is running ==="
echo "Starting Ongamecloud WebSocket server..."
php artisan ongamecloud:websocket 2>&1 | tee storage/logs/websocket.log &
WEBSOCKET_PID=$!
echo "WebSocket server started with PID: $WEBSOCKET_PID"
sleep 2
if ! kill -0 $WEBSOCKET_PID 2>/dev/null; then
echo "ERROR: WebSocket server crashed immediately!"
echo "Last 50 lines of websocket.log:"
tail -50 storage/logs/websocket.log
fi
echo "Logs will appear below..."
echo ""
mkdir -p storage/logs
touch storage/logs/laravel.log
tail -f storage/logs/*.log 2>/dev/null &
wait $NGINX_PID