-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrun_no_in_docker.sh
68 lines (58 loc) · 1.6 KB
/
run_no_in_docker.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
#!/bin/sh
SERVICE=$(cd $(dirname $0); pwd | awk -F '/' '{print $(NF)}')
SERVICE_DIR="/usr/app/${SERVICE}/${SERVICE}"
MEMORY=${MEMORY:-"1024m"}
Start() {
mem=$1
echo ${mem}
if [ -z "$mem" ];then
mem=$MEMORY
fi
proc=$(ps -ef | grep "$SERVICE_DIR" | grep -v grep | wc -l)
if [[ $proc != 0 ]];then
exit 5
fi
java -server -Xms${mem} -Xmx${mem} -jar "$SERVICE_DIR".jar $ARGS >> /usr/logs/${SERVICE}/${SERVICE}.log 2>&1 &
}
Stop() {
in_stop_count=0
while true; do
proc=$(ps -ef | grep "$SERVICE_DIR" | grep -v grep | wc -l)
if [[ $proc != 0 ]]; then
if [[ $in_stop_count == 0 ]]; then
if ps -ef | grep "$SERVICE_DIR" | grep -v grep | awk '{print $1}'| xargs kill -5 > /dev/null; then
echo "Attempt to gracefully close the ${SERVICE}"
else
echo "kill command exec error..."
break
fi
elif [[ $in_stop_count -gt 30 ]]; then
echo "Close timeout, Forcefully close the ${SERVICE}"
ps -ef | grep "$SERVICE_DIR" | grep -v grep | awk '{print $1}'| xargs kill -9
break
else
echo "Closed and waited for $in_stop_count seconds"
fi
in_stop_count=$((in_stop_count+1))
sleep 1
else
echo "${SERVICE} not running now..."
break
fi
done
}
Restart() {
Stop
Start
}
case $1 in
start|run)
Start $2
;;
stop)
Stop
;;
restart)
Restart
;;
esac