Update Dockerfile
Browse files- Dockerfile +29 -3
Dockerfile
CHANGED
@@ -202,26 +202,48 @@ wait_for_port() {
|
|
202 |
# Function to start the frontend server
|
203 |
start_frontend() {
|
204 |
cd /app/web
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
# Ensure the output log directory exists
|
208 |
touch output.log
|
209 |
echo "Starting Next.js server at $(date)" > output.log
|
|
|
210 |
# Configure Next.js to listen on all interfaces
|
211 |
export HOSTNAME="0.0.0.0"
|
212 |
export NODE_ENV=production
|
213 |
export PORT=3000
|
|
|
214 |
# Start the server with proper error handling
|
215 |
node server.js >> output.log 2>&1 &
|
216 |
local pid=$!
|
217 |
echo "Frontend server started with PID: $pid"
|
218 |
-
|
|
|
219 |
sleep 5
|
220 |
if ! kill -0 $pid 2>/dev/null; then
|
221 |
echo "Frontend server failed to start. Last 50 lines of logs:"
|
222 |
tail -n 50 output.log
|
223 |
return 1
|
224 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
return 0
|
226 |
}
|
227 |
|
@@ -242,6 +264,10 @@ monitor_services() {
|
|
242 |
if [ $restart_count -lt $max_restarts ]; then
|
243 |
restart_count=$((restart_count + 1))
|
244 |
echo "Restart attempt $restart_count of $max_restarts"
|
|
|
|
|
|
|
|
|
245 |
if start_frontend; then
|
246 |
echo "Frontend server restarted successfully"
|
247 |
# Reset counter on successful restart
|
|
|
202 |
# Function to start the frontend server
|
203 |
start_frontend() {
|
204 |
cd /app/web
|
205 |
+
echo "Cleaning up any existing Node.js processes..."
|
206 |
+
# Kill any existing node processes more thoroughly
|
207 |
+
pkill -9 -f "node server.js" || true
|
208 |
+
# Wait a moment to ensure ports are released
|
209 |
+
sleep 2
|
210 |
+
# Check if port is still in use
|
211 |
+
if netstat -tulpn | grep ":3000" > /dev/null; then
|
212 |
+
echo "Port 3000 is still in use. Attempting to force cleanup..."
|
213 |
+
# Find and kill any process using port 3000
|
214 |
+
fuser -k 3000/tcp || true
|
215 |
+
sleep 2
|
216 |
+
fi
|
217 |
+
|
218 |
# Ensure the output log directory exists
|
219 |
touch output.log
|
220 |
echo "Starting Next.js server at $(date)" > output.log
|
221 |
+
|
222 |
# Configure Next.js to listen on all interfaces
|
223 |
export HOSTNAME="0.0.0.0"
|
224 |
export NODE_ENV=production
|
225 |
export PORT=3000
|
226 |
+
|
227 |
# Start the server with proper error handling
|
228 |
node server.js >> output.log 2>&1 &
|
229 |
local pid=$!
|
230 |
echo "Frontend server started with PID: $pid"
|
231 |
+
|
232 |
+
# Wait a bit to ensure process is stable and check its status
|
233 |
sleep 5
|
234 |
if ! kill -0 $pid 2>/dev/null; then
|
235 |
echo "Frontend server failed to start. Last 50 lines of logs:"
|
236 |
tail -n 50 output.log
|
237 |
return 1
|
238 |
fi
|
239 |
+
|
240 |
+
# Verify the port is actually being used by our process
|
241 |
+
if ! netstat -tulpn | grep ":3000.*$pid" > /dev/null; then
|
242 |
+
echo "Frontend server is running but not bound to port 3000. Last 50 lines of logs:"
|
243 |
+
tail -n 50 output.log
|
244 |
+
return 1
|
245 |
+
fi
|
246 |
+
|
247 |
return 0
|
248 |
}
|
249 |
|
|
|
264 |
if [ $restart_count -lt $max_restarts ]; then
|
265 |
restart_count=$((restart_count + 1))
|
266 |
echo "Restart attempt $restart_count of $max_restarts"
|
267 |
+
# Force cleanup before restart
|
268 |
+
pkill -9 -f "node server.js" || true
|
269 |
+
fuser -k 3000/tcp || true
|
270 |
+
sleep 2
|
271 |
if start_frontend; then
|
272 |
echo "Frontend server restarted successfully"
|
273 |
# Reset counter on successful restart
|