forked from askomics/flaskomics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all.sh
executable file
·98 lines (81 loc) · 2.15 KB
/
run_all.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! /bin/bash
# Paths
dir_askomics=$(dirname "$0")
dir_venv="$dir_askomics/venv"
dir_node_modules="$dir_askomics/node_modules"
activate="$dir_venv/bin/activate"
ntasks=1
error=0
function usage() {
echo "Usage: $0 (-d { dev | prod })"
echo " -d deployment mode (default: production)"
echo " -c celery max parallel tasks (default: 1)"
}
while getopts "hd:c:" option; do
case $option in
h)
usage
exit 0
;;
d)
depmode=$OPTARG
;;
c)
ntasks=$OPTARG
;;
esac
done
case $depmode in
prod|production|"")
flask_depmod="production"
npm_depmode="prod"
flask_command="gunicorn -b 0.0.0.0:5000 app"
;;
dev|development)
flask_depmod="development"
npm_depmode="dev"
flask_command="flask run --host=0.0.0.0"
;;
*)
echo "-d $depmode: wrong deployment mode"
usage
exit 1
esac
# Exports
export FLASK_ENV=$flask_depmod
export FLASK_APP="app"
echo "Removing python cache ..."
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
if [[ -f $activate ]]; then
echo "Sourcing Python virtual environment ..."
source ${dir_venv}/bin/activate
else
echo "No virtual environment found. Run install.sh first."
error=1
fi
if [[ ! -d $dir_node_modules ]]; then
echo "No node_modules directory found. Run install.sh first."
error=1
fi
if [[ $error > 0 ]]; then
exit 1
fi
# Create config file
config_template_path="$dir_askomics/config/askomics.ini.template"
config_path="$dir_askomics/config/askomics.ini"
if [[ ! -f $config_path ]]; then
cp $config_template_path $config_path
fi
trap 'kill 0' INT
# Run
echo "Building JS ..."
npm run $npm_depmode &
echo "Starting celery ..."
if [[ $flask_depmod == "development" ]]; then
watchmedo auto-restart -d ${dir_askomics}/askomics --recursive -p '*.py' --ignore-patterns='*.pyc' -- celery -A askomics.tasks.celery worker -Q default -c ${ntasks} -n default -l info &
else
celery -A askomics.tasks.celery worker -Q default -c ${ntasks} -n default -l info &
fi
echo "Starting server ..."
$flask_command &
wait