forked from microsoft/aerial_wildlife_detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIDE.sh
executable file
·98 lines (87 loc) · 3.09 KB
/
AIDE.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
# Launches or terminates AIDE with all the correct modules,
# including Celery, if required.
# The information on which modules and services to run come
# from the following two environment variables:
# * AIDE_CONFIG_PATH
# * AIDE_MODULES
#
# 2020-21 Benjamin Kellenberger
function start {
IFS=',' read -ra ADDR <<< "$AIDE_MODULES"
# Celery
# numCeleryModules=0;
# for i in "${ADDR[@]}"; do
# module="$(echo "$i" | tr '[:upper:]' '[:lower:]')";
# if [ "$module" == "labelui" || "$module" == "aiworker" ] || [ "$module" == "fileserver" ]; then
# ((numCeleryModules++));
# fi
# done
# if [ $numCeleryModules -gt 0 ]; then
launchCeleryBeat=false
IFS=',' read -ra ADDR <<< "$AIDE_MODULES"
for i in "${ADDR[@]}"; do
module="$(echo "$i" | tr '[:upper:]' '[:lower:]')";
if [ "$module" == "fileserver" ]; then
folderWatchInterval=$(python util/configDef.py --section=FileServer --parameter=watch_folder_interval --fallback=60);
if [ $folderWatchInterval -gt 0 ]; then
launchCeleryBeat=true;
fi
fi
done
if [ $launchCeleryBeat ]; then
# folder watching interval specified; enable Celery beat
tempDir="$(python util/configDef.py --section=FileServer --parameter=tempfiles_dir --fallback=/tmp)/aide/celery/";
mkdir -p $tempDir;
celery -A celery_worker worker -B -s $tempDir --hostname aide@%h &
else
celery -A celery_worker worker --hostname aide@%h &
fi
# fi
# AIDE
numHTTPmodules=0;
for i in "${ADDR[@]}"; do
module="$(echo "$i" | tr '[:upper:]' '[:lower:]')";
if [ "$module" != "aiworker" ]; then
((numHTTPmodules++));
fi
done
if [ $numHTTPmodules -gt 0 ]; then
# perform verbose pre-flight checks
python setup/assemble_server.py --migrate_db 1
if [ $? -eq 0 ]; then
# pre-flight checks succeeded; get host and port from configuration file
host=$(python util/configDef.py --section=Server --parameter=host)
port=$(python util/configDef.py --section=Server --parameter=port)
numWorkers=$(python util/configDef.py --section=Server --parameter=numWorkers --type=int --fallback=6)
debug="$(echo "$2" | tr '[:upper:]' '[:lower:]')";
if [ "$debug" == "debug" ]; then
debug="--log-level debug";
else
debug="";
fi
gunicorn application:app --bind=$host:$port --workers=$numWorkers $debug
else
echo -e "\033[0;31mPre-flight checks failed; aborting launch of AIDE.\033[0m"
fi
else
echo "Machine only runs as an AIWorker; skipping set up of HTTP web server..."
fi
}
function stop {
celery -A celery_worker control shutdown;
pkill gunicorn;
}
function restart {
stop;
start;
}
mode=$1;
if [ "$mode" == "start" ]; then
start;
elif [ "$mode" == "restart" ]; then
restart;
elif [ "$mode" == "stop" ]; then
stop;
else
echo "Usage: AIDE.sh {start|restart|stop} [debug]"
fi