forked from soapower/soapower
-
Notifications
You must be signed in to change notification settings - Fork 1
/
soapowerctl.sh
executable file
·265 lines (224 loc) · 7.17 KB
/
soapowerctl.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
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
#
# Soapower Control Shell Script (soapowerctl.sh)
#
# This script could be used with a standard installation of soapower.
# Read installation's documentation on http://soapower.github.io/soapower
#
# ./soapower.ctl.sh start : start soapower
# ./soapower.ctl.sh stop : stop soapower
# ./soapower.ctl.sh restart : restart soapower
# ./soapower.ctl.sh configtest : check the configuration
# ./soapower.ctl.sh status : display soapower status (port regardless)
#
# YOU DOESN'T NEED TO MODIFY THIS SCRIPT.
#
#
#############################################################
########################################
# Init vars
# You can define SOAPOWER_HOME and SOAPOWER_HTTP_PORT
# in you env (ex: .profile).
# Default values :
# - SOAPOWER_HOME : /opt/soapower
# - SOAPOWER_HTTP_PORT : 9010
########################################
if [[ -z "${SOAPOWER_HOME}" ]]; then
SOAPOWER_HOME="/opt/soapower"
fi
if [[ -z "${SOAPOWER_HTTP_PORT}" ]]; then
SOAPOWER_HTTP_PORT=9010
fi
########################################
# Display Usage
# Display how to use soapowerctl.sh
########################################
display_usage() {
echo -e "\nUsage:\n$0 [run|start|stop|restart|configtest|status] \n"
return 0
}
########################################
# Configtest
# Check the configuration of soapower :
# - chmod +x start file
# - check start file with dir lib/
# - check java and version (>=1.6)
########################################
configtest() {
ERROR=0
export SOAPOWER_CURRENT="${SOAPOWER_HOME}/current"
echo "Soapower Home: ${SOAPOWER_HOME}, port : ${SOAPOWER_HTTP_PORT}"
echo "Soapower Current: ${SOAPOWER_CURRENT}"
echo "Checking bin/soapower file..."
chmod +x ${SOAPOWER_CURRENT}/bin/soapower
if [ $? -ne 0 ]; then
echo "ERROR : Failed to chmod +x bin/soapower, please check your installation"
ERROR=1
fi
cd ${SOAPOWER_CURRENT}
JAR_FILE=`cd lib && ls *soapower* | grep -v assets`
grep ${JAR_FILE} bin/soapower >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR : bin/soapower file does not match with jar in dir lib/, please check your installation"
ERROR=1
fi
echo "Checking java version..."
if type -p java >/dev/null 2>&1 ; then
JAVA_VER=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q')
if [ "$JAVA_VER" -ge 17 ]; then
echo "ok, java is 1.7 or newer"
else
echo "ERROR : java version is too old..."
ERROR=1
fi
else
echo "ERROR : no java found in PATH"
ERROR=1
fi
IS_MONGO_LISTEN=`lsof -iTCP -sTCP:LISTEN | grep mongod`
if [ $? -ne 0 ]; then
echo "ERROR : please check if mongodb is running" ;
ERROR=1
else
echo "ok, mongodb is running" ;
fi
return ${ERROR}
}
########################################
# Run
# Use start Method to start Soapower
# without nohup command
########################################
run() {
start "run"
}
########################################
# Start
# Start an instance of soapower
# on http.port ${SOAPOWER_HTTP_PORT}
# Do nothing if Soapower is already started.
# If Soapower is not started :
# - Deleting RUNNING_PID file if necessary
# - Start with nohup command
# - Call action "status"
# - Check pid on ${SOAPOWER_HTTP_PORT}
########################################
start() {
RUN=$1
ERROR=0
ps -ef | grep java | grep soapower | grep "http.port=${SOAPOWER_HTTP_PORT}" | grep -v grep >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Soapower is already started on port ${SOAPOWER_HTTP_PORT}. Please stop before" ;
return 1;
fi
if [ -f ${SOAPOWER_CURRENT}/RUNNING_PID ]; then
echo "WARN : there is ${SOAPOWER_CURRENT}/RUNNING_PID file. Deleting it and continue starting..."
rm ${SOAPOWER_CURRENT}/RUNNING_PID
if [ $? -ne 0 ]; then
echo "ERROR : can't deleting ${SOAPOWER_CURRENT}/RUNNING_PID file. Abort Starting Soapower"
return 1;
fi
fi
CMD="${SOAPOWER_CURRENT}/bin/soapower -Dhttp.port=${SOAPOWER_HTTP_PORT} -J-server -Dconfig.file=conf/application.conf -Dlogger.file=conf/prod-logger.xml"
if [ "x${RUN}" = "xrun" ]; then
echo "Running Soapower..."
${CMD}
else
echo "Starting Soapower (with nohup)..."
nohup ${CMD} >/dev/null 2>&1 &
if [ $? -ne 0 ]; then
echo "ERROR while starting soapower. Please run this command and check the log file:"
echo "$CMD"
ERROR=1
fi
sleep 3
status
ps -ef | grep java | grep soapower | grep "http.port=${SOAPOWER_HTTP_PORT}" | grep -v grep >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR while starting soapower. Please run this command and check the log file:"
echo "$CMD"
ERROR=1
fi
return ${ERROR}
fi;
}
########################################
# Stop
# Stop instance of soapower running
# on http.port ${SOAPOWER_HTTP_PORT}
########################################
stop() {
ps -ef | grep java | grep soapower | grep "http.port=${SOAPOWER_HTTP_PORT}" | grep -v grep >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Soapower is already stopped on http.port ${SOAPOWER_HTTP_PORT}"
return 0
fi
echo "Stopping Soapower (on running http.port ${SOAPOWER_HTTP_PORT})..."
ps -ef | grep java | grep soapower | grep "http.port=${SOAPOWER_HTTP_PORT}" | grep -v grep | while read a b c; do kill -15 $b ; done
sleep 4
# kill if necessary
ps -ef | grep java | grep soapower | grep "http.port=${SOAPOWER_HTTP_PORT}" | grep -v grep | while read a b c; do echo "Normal TERM failed, kill -9 soapower..." kill -9 ${b} ; done
return 0
}
########################################
# Status
# Display the status of all instances of soapower
# with ps command.
########################################
status() {
echo "Status (all instances of soapower are scanned):"
ps -ef | grep java | grep soapower | grep -v grep | while read a b c; do
PORT=$(echo ${c} | sed 's/\(.*\)-Dhttp.port.\([0-9]*\)\(.*\)/\2/; 1q')
echo "Soapower is started with pid:$b and http.port:${PORT}"
done
ps -ef | grep java | grep soapower | grep -v grep >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Soapower is stopped"
fi
return 0
}
########################################
# Restart
# Run stop then start action
########################################
restart() {
stop
start
}
########################################
# Action
# Run configtest before run an action. If
# the configtest failed, return directly
# param $1 : action to run
########################################
action() {
configtest
if [ $? -eq 0 ]; then
$1
ERROR=$?
fi
return ${ERROR}
}
#########################
# MAIN
#########################
ACMD="$1"
ARGV="$@"
ERROR=0
case ${ACMD} in
start|stop|restart|run)
action ${ACMD}
ERROR=$?
;;
configtest)
configtest
ERROR=$?
;;
status)
status
;;
*)
display_usage
ERROR=$?
esac
exit ${ERROR}