File size: 798 Bytes
fd1fd71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
clear
# Load environment variables from .env file (if it exists)
if [[ -f .env ]]; then
  source .env
fi

# Get the port, prioritizing environment variables and then defaulting to 80
PORT="${PORT:-${SERVER_PORT:-80}}"

# Check if the port is a valid number
if ! [[ "$PORT" =~ ^[0-9]+$ ]]; then
  echo "Invalid port: $PORT. Please set a valid number in .env or your environment." >&2  # Redirect to stderr
  exit 1
fi

# Define a function to start Gunicorn
start_gunicorn() {
  echo "Starting Gunicorn on port $PORT..."
  exec gunicorn main:app -b 0.0.0.0:$PORT -w 8 --timeout 600
}

# Start Gunicorn initially
start_gunicorn

# Restart loop in case of crashes
while true; do
  echo "Gunicorn exited. Restarting in 5 seconds..." >&2  # Redirect to stderr
  sleep 5
  start_gunicorn
done