-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
41 lines (32 loc) · 933 Bytes
/
entrypoint.sh
File metadata and controls
41 lines (32 loc) · 933 Bytes
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
#!/bin/sh
set -e
# Start the FastAPI backend
cd /backend || { echo "Backend directory not found"; exit 1; }
echo "Starting FastAPI backend"
# Start Uvicorn with proper host binding
uvicorn server:app --host 0.0.0.0 --port 8001 &
BACKEND_PID=$!
echo "Waiting for backend to start..."
sleep 30
if ! kill -0 $BACKEND_PID 2>/dev/null; then
echo "Backend failed to start at initialization, exiting"
exit 1
fi
# Start Nginx
nginx -g 'daemon off;' &
NGINX_PID=$!
# Handle termination signals
trap 'kill $BACKEND_PID $NGINX_PID; exit 0' SIGTERM SIGINT
# Check if processes are still running
while kill -0 $BACKEND_PID 2>/dev/null && kill -0 $NGINX_PID 2>/dev/null; do
sleep 1
done
# If we get here, one of the processes died
if kill -0 $BACKEND_PID 2>/dev/null; then
echo "Nginx died, shutting down backend..."
kill $BACKEND_PID
else
echo "Backend died, shutting down nginx..."
kill $NGINX_PID
fi
exit 1