#!/bin/bash

BASE="/home/lastchar/lastcharter_control_center"

cd "$BASE"

source venv/bin/activate

pkill -f "gunicorn.*control_center:app" || true

sleep 3

nohup gunicorn \
--workers 3 \
--bind 127.0.0.1:8898 \
--timeout 120 \
--access-logfile "$BASE/logs/gunicorn_access.log" \
--error-logfile "$BASE/logs/gunicorn_error.log" \
control_center:app \
>> "$BASE/logs/gunicorn_master.log" 2>&1 &

sleep 3

pgrep -f "gunicorn.*control_center:app" | head -1 > "$BASE/runtime/gunicorn.pid"

echo "GUNICORN PID=$(cat $BASE/runtime/gunicorn.pid)"
