forked from openbaton/NFVO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenbaton.sh
executable file
·254 lines (214 loc) · 6.01 KB
/
openbaton.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
source ./gradle.properties
_version=${version}
_openbaton_base="/opt/openbaton/"
_message_queue_base="apache-activemq-5.11.3"
_openbaton_config_file=/etc/openbaton/openbaton.properties
function start_activemq_linux {
sudo ${_openbaton_base}/${_message_queue_base}/bin/activemq start
if [ $? -ne 0 ]; then
echo "ERROR: activemq is not running properly (check the problem in ${_openbaton_base}/${_message_queue_base}/data/activemq.log) "
exit 1
fi
}
function start_activemq_osx {
sudo ${_openbaton_base}/${_message_queue_base}/bin/macosx/activemq start
if [ $? -ne 0 ]; then
echo "ERROR: activemq is not running properly (check the problem in ${_openbaton_base}/${_message_queue_base}/data/activemq.log) "
exit 1
fi
}
function check_activemq {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
ps -aux | grep -v grep | grep activemq > /dev/null
if [ $? -ne 0 ]; then
echo "activemq is not running, let's try to start it..."
start_activemq_linux
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
ps aux | grep -v grep | grep activemq > /dev/null
if [ $? -ne 0 ]; then
echo "activemq is not running, let's try to start it..."
start_activemq_osx
fi
fi
}
function check_rabbitmq {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
ps -aux | grep -v grep | grep rabbitmq > /dev/null
if [ $? -ne 0 ]; then
echo "rabbit is not running, let's try to start it..."
start_rabbitmq
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
ps aux | grep -v grep | grep rabbitmq > /dev/null
if [ $? -ne 0 ]; then
echo "rabbitmq is not running, let's try to start it..."
start_rabbitmq
fi
fi
}
function start_rabbitmq {
`rabbitmq-server -detached`
if [ $? -ne 0 ]; then
echo "ERROR: rabbitmq is not running properly (check the problem in /var/log/rabbitmq.log) "
exit 1
fi
}
function start_mysql_osx {
sudo /usr/local/mysql/support-files/mysql.server start
}
function start_mysql_linux {
sudo service mysql start
}
function check_mysql {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
result=$(pgrep mysql | wc -l);
if [ ${result} -eq 0 ]; then
read -p "mysql is down, would you like to start it ([y]/n):" yn
case $yn in
[Yy]* ) start_mysql_linux ; break;;
[Nn]* ) echo "you can't proceed withuot having mysql up and running"
exit;;
* ) start_mysql_linux;;
esac
else
echo "mysql is already running.."
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
mysqladmin status
result=$?
if [ "${result}" -eq "0" ]; then
echo "mysql service running..."
else
read -p "mysql is down, would you like to start it ([y]/n):" yn
case $yn in
[Yy]* ) start_mysql_osx ; break;;
[Nn]* ) exit;;
* ) start_mysql_osx;;
esac
fi
fi
}
function check_already_running {
result=$(screen -ls | grep openbaton | wc -l);
if [ "${result}" -ne "0" ]; then
echo "openbaton is already running.."
exit;
fi
}
function start {
if [ ! -d build/ ]
then
compile
fi
# check_activemq
check_rabbitmq
#check_mysql
check_already_running
if [ 0 -eq $? ]
then
#screen -X eval "chdir $PWD"
screen -c screenrc -d -m -S openbaton -t nfvo java -jar "build/libs/openbaton-$_version.jar" --spring.config.location=file:${_openbaton_config_file}
#screen -c screenrc -r -p 0
fi
}
function stop {
if screen -list | grep "openbaton"; then
screen -S openbaton -p 0 -X stuff "exit$(printf \\r)"
fi
}
function restart {
kill
start
}
function kill {
if screen -list | grep "openbaton"; then
screen -ls | grep openbaton | cut -d. -f1 | awk '{print $1}' | xargs kill
fi
}
function compile {
./gradlew build -x test
}
function tests {
./gradlew test
}
function update {
echo "~~~~~~~~~~~~~~~~~~~~OpenBaton UPDATE~~~~~~~~~~~~~~~~~~~~"
echo " "
echo " updating to version 0.15"
echo " "
echo "installing new requirements:"
echo "*) rabbitmq"
if [[ "$OSTYPE" == "linux-gnu" ]]; then
sudo apt-get update
sudo apt-get install -y rabbitmq-server
ulimit -S -n 4096
sudo rabbitmqctl add_user admin openbaton
sudo rabbitmqctl set_user_tags admin administrator
sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
sudo rabbitmq-plugins enable rabbitmq_management
sudo service rabbitmq-server restart
elif [[ "$OSTYPE" == "darwin"* ]]; then
brew update
brew install rabbitmq
ulimit -S -n 4096
rabbitmqctl add_user admin openbaton
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
rabbitmq-plugins enable rabbitmq_management
rabbitmqctl stop
rabbitmq-server start -detached
fi
}
function clean {
./gradlew clean
}
function end {
exit
}
function usage {
echo -e "Open-Baton\n"
echo -e "Usage:\n\t ./openbaton.sh [compile|start|stop|test|kill|clean]"
}
##
# MAIN
##
if [ $# -eq 0 ]
then
usage
exit 1
fi
declare -a cmds=($@)
for (( i = 0; i < ${#cmds[*]}; ++ i ))
do
case ${cmds[$i]} in
"clean" )
clean ;;
"sc" )
clean
compile
start ;;
"start" )
start ;;
"update" )
update ;;
"stop" )
stop ;;
"restart" )
restart ;;
"compile" )
compile ;;
"kill" )
kill ;;
"test" )
tests ;;
* )
usage
end ;;
esac
if [[ $? -ne 0 ]];
then
exit 1
fi
done