forked from rmegret/labelbee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gunicorn_start.sh
executable file
·36 lines (27 loc) · 1020 Bytes
/
gunicorn_start.sh
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
#!/bin/bash
# From https://stackoverflow.com/a/60652702
checkEnvVariable() {
local env_var=
env_var=$(declare -p "$1")
if ! [[ -v $1 && $env_var =~ ^declare\ -x ]]; then
echo "Error: Environment variable '$1' is not defined"
exit 1
fi
}
# Define all vars in a script and source it
# source gunicorn_config.sh
checkEnvVariable SECRET_KEY
checkEnvVariable DB_URL
checkEnvVariable DB_PASSWORD
checkEnvVariable DB_USER
checkEnvVariable LABELBEE_PORT
checkEnvVariable LABELBEE_APPDIR
checkEnvVariable LABELBEE_LOGDIR
checkEnvVariable CONDA_EXE
GUNICORN_PIDFILE="$LABELBEE_LOGDIR"/labelbee.pid
GUNICORN_LOG="$LABELBEE_LOGDIR"/gunicorn_error_logs.log
# Setup CONDA, then activate labelbee env
eval "$($CONDA_EXE shell.bash hook)"
conda activate labelbee
# May be a good idea to check https://docs.gunicorn.org/en/latest/configure.html
gunicorn -p "$GUNICORN_PIDFILE" -b 127.0.0.1:$LABELBEE_PORT --chdir "$LABELBEE_APPDIR" manage:app -w 1 --threads 12 --timeout 300 --log-file "$GUNICORN_LOG" --daemon