2
2
# Author: Mihai Criveti
3
3
# Description: Run Gunicorn production server (optionally with TLS)
4
4
5
- # Determine script directory
5
+ # ──────────────────────────────
6
+ # Locate script directory
7
+ # ──────────────────────────────
6
8
SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
7
9
8
- # Attempt to activate a venv if not already active
10
+ # ──────────────────────────────
11
+ # Activate virtual-env (if any)
12
+ # ──────────────────────────────
9
13
if [[ -z " $VIRTUAL_ENV " ]]; then
10
14
# If a known venv path exists (like your custom .venv location), activate it
11
15
if [[ -f " ${HOME} /.venv/mcpgateway/bin/activate" ]]; then
@@ -20,6 +24,22 @@ if [[ -z "$VIRTUAL_ENV" ]]; then
20
24
fi
21
25
fi
22
26
27
+ # ──────────────────────────────
28
+ # Identify Python interpreter
29
+ # ──────────────────────────────
30
+ if [[ -n " ${VIRTUAL_ENV:- } " && -x " ${VIRTUAL_ENV} /bin/python" ]]; then
31
+ PYTHON=" ${VIRTUAL_ENV} /bin/python"
32
+ elif command -v python3 > /dev/null 2>&1 ; then
33
+ PYTHON=" $( command -v python3) "
34
+ elif command -v python > /dev/null 2>&1 ; then
35
+ PYTHON=" $( command -v python) "
36
+ else
37
+ echo " ✘ No suitable Python interpreter found (tried python3, python)."
38
+ exit 1
39
+ fi
40
+
41
+ echo " 🐍 Using Python interpreter: ${PYTHON} "
42
+
23
43
cat << "EOF "
24
44
███╗ ███╗ ██████╗██████╗ ██████╗ █████╗ ████████╗███████╗██╗ ██╗ █████╗ ██╗ ██╗
25
45
████╗ ████║██╔════╝██╔══██╗ ██╔════╝ ██╔══██╗╚══██╔══╝██╔════╝██║ ██║██╔══██╗╚██╗ ██╔╝
@@ -54,8 +74,14 @@ if [[ "${SSL}" == "true" ]]; then
54
74
echo " ✓ TLS enabled – using ${CERT_FILE} / ${KEY_FILE} "
55
75
fi
56
76
57
- # Initialize databases
58
- " $PYTHON " -m mcpgateway.db
77
+ # ──────────────────────────────
78
+ # Database migrations / checks
79
+ # ──────────────────────────────
80
+ " ${PYTHON} " -m mcpgateway.db
81
+ if [[ $? -ne 0 ]]; then
82
+ echo " ✘ Database migration/check failed. Please resolve issues before starting the server."
83
+ exit 1
84
+ fi
59
85
60
86
exec gunicorn -c gunicorn.config.py \
61
87
--worker-class uvicorn.workers.UvicornWorker \
0 commit comments