-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.sh
executable file
·130 lines (89 loc) · 3.4 KB
/
app.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /bin/bash
####################### LOCATION VARS ###########################
OBJECT_DETECTOR_INSTALLED="false"
AGENTS_PATH="src/agents"
cd $AGENTS_PATH
function print_parameters {
echo -e "Usage: app.sh <arg>"
echo -e "Common args:"
echo -e " start Launches the necessary processes to start the application"
echo -e " stop Stops all application processes"
echo -e " status Displays the status of application processes"
}
function kill_process {
PID=`ps -eaf | grep $1 | grep -v grep | awk '{print $2}'`
if [[ "" != "$PID" ]]; then
echo "- Stopping $1 "
kill -9 $PID
else
echo "- $1 was already stopped"
fi
}
function check_process {
PID=`ps -eaf | grep $1 | grep -v grep | awk '{print $2}'`
if [[ "" != "$PID" ]]; then
echo "- $1 is running"
else
echo "- $1 is NOT running"
fi
}
if [ $# -eq 1 ]; then
case $1 in
"start")
echo "========================================================"
echo "Starting api agent agent worker..."
echo "========================================================"
celery -A api_agent.celery worker -n api_agent -l INFO -c 1 -Q api_agent > /dev/null 2>&1 & disown
sleep 2
if [[ $OBJECT_DETECTOR_INSTALLED == "true" ]]; then
echo "========================================================"
echo "Starting celery motion agent worker..."
echo "========================================================"
celery -A motion_agent.celery worker -n motion_agent -l INFO -c 1 -Q motion_agent > /dev/null 2>&1 & disown
sleep 1
fi
echo "========================================================"
echo "Starting api agent..."
echo "========================================================"
python3 api_agent.py > /dev/null 2>&1 & disown
sleep 3
echo "========================================================"
echo "Starting telegram bot..."
echo "========================================================"
python3 telegram_bot.py > /dev/null 2>&1 & disown
sleep 2
if [[ $OBJECT_DETECTOR_INSTALLED == "true" ]]; then
echo "========================================================"
echo "Starting object detector agent..."
echo "========================================================"
python3 object_detector_agent.py > /dev/null 2>&1 & disown
fi
;;
"stop")
echo "========================================================"
echo "Stopping app process..."
echo "========================================================"
kill_process api_agent.celery
kill_process api_agent.py
kill_process telegram_bot.py
if [[ $OBJECT_DETECTOR_INSTALLED == "true" ]]; then
kill_process motion_agent.celery
kill_process object_detector_agent.py
fi
;;
"status")
check_process api_agent.celery
if [[ $OBJECT_DETECTOR_INSTALLED == "true" ]]; then
check_process motion_agent.celery
check_process object_detector_agent.py
fi
check_process api_agent.py
check_process telegram_bot.py
;;
*)
print_parameters
;;
esac
else
print_parameters
fi