-
Notifications
You must be signed in to change notification settings - Fork 20
/
generic-vnfm.sh
executable file
·183 lines (158 loc) · 4.48 KB
/
generic-vnfm.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
#!/bin/bash
source gradle.properties
_openbaton_base="/opt/openbaton"
_generic_base="${_openbaton_base}/generic-vnfm"
_openbaton_config_file="/etc/openbaton/openbaton-vnfm-generic.properties"
_version=${version}
_screen_session_name="openbaton"
_screen_name="generic-vnfm"
function checkBinary {
echo -n " * Checking for '$1'..."
if command -v $1 >/dev/null 2>&1; then
echo "OK"
return 0
else
echo >&2 "FAILED."
return 1
fi
}
_ex='sh -c'
if [ "$_user" != 'root' ]; then
if checkBinary sudo; then
_ex='sudo -E sh -c'
elif checkBinary su; then
_ex='su -c'
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 {
$_ex '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 check_already_running {
pgrep -f generic-vnfm-${_version}.jar
if [ "$?" -eq "0" ]; then
echo "generic-vnfm is already running.."
exit;
fi
}
function start {
echo "Starting the Generic-VNFM"
# if not compiled, compile
if [ ! -d ${_generic_base}/build/ ]
then
compile
fi
check_rabbitmq
check_already_running
if [ "${1}" == "true" ]; then
if [ -f ${_openbaton_config_file} ]; then
java -jar "${_generic_base}/build/libs/generic-vnfm-${_version}.jar" --spring.config.location=file:${_openbaton_config_file}
else
java -jar "${_generic_base}/build/libs/generic-vnfm-${_version}.jar"
fi
else
screen_exists=$(screen -ls | grep "\.${_screen_session_name}" | wc -l);
if [ "${screen_exists}" -eq "0" ]; then
echo "Starting the Generic-VNFM in a new screen session (attach to the screen with screen -x openbaton)"
if [ -f ${_openbaton_config_file} ]; then
screen -c screenrc -d -m -S ${_screen_session_name} -t ${_screen_name} java -jar "${_generic_base}/build/libs/generic-vnfm-${_version}.jar" --spring.config.location=file:${_openbaton_config_file}
else
screen -c screenrc -d -m -S ${_screen_session_name} -t ${_screen_name} java -jar "${_generic_base}/build/libs/generic-vnfm-${_version}.jar"
fi
else
echo "Starting the Generic-VNFM in the existing screen session (attach to the screen with screen -x openbaton)"
if [ -f ${_openbaton_config_file} ]; then
screen -S ${_screen_session_name} -X screen -t ${_screen_name} java -jar "${_generic_base}/build/libs/generic-vnfm-${_version}.jar" --spring.config.location=file:${_openbaton_config_file}
else
screen -S ${_screen_session_name} -X screen -t ${_screen_name} java -jar "${_generic_base}/build/libs/generic-vnfm-${_version}.jar"
fi
fi
fi
}
function stop {
if screen -list | grep "\.${_screen_session_name}" > /dev/null ; then
screen -S ${_screen_session_name} -p ${_screen_name} -X stuff '\003'
fi
}
function restart {
kill
start
}
function kill {
pkill -f generic-vnfm-${_version}.jar
}
function compile {
./gradlew build -x test
}
function tests {
./gradlew test
}
function clean {
./gradlew clean
}
function end {
exit
}
function usage {
echo -e "Open-Baton generic-vnfm\n"
echo -e "Usage:\n\t ./generic-vnfm.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_fg" )
start "true" ;;
"start" )
start ;;
"stop" )
stop ;;
"restart" )
restart ;;
"compile" )
compile ;;
"kill" )
kill ;;
"test" )
tests ;;
* )
usage
end ;;
esac
if [[ $? -ne 0 ]];
then
exit 1
fi
done