killws.sh
2.9 KB
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
#!/bin/bash
################################################################
#@Authro Lijian
#@Date 2007-05-22
################################################################
BASE_BIN_DIR=`dirname $0`
#import home var env
. $BASE_BIN_DIR/env.sh
TIMESTAMP=`date +%Y_%m_%d_%H:%M`
HOST_NAME=`hostname`
LOG_DIR=$WEB_APP_HOME/logs
JBOSS_CHECK_LOG="$LOG_DIR/jboss_stdout.log"
JBOSS_BASE_DIR=$WEB_APP_HOME/.jboss/default
TOMCAT_BASE_DIR=$WEB_APP_HOME/.tomcat
LOCAL_IP=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
REMOVE_URL="http://ufoapi.yohoops.org/service_control/unregister?ip=$LOCAL_IP&context=ufo-gateway"
stop_jboss()
{
JBOSS_JAVA_PID=`get_jboss_pid`
if [ ! -z "$JBOSS_JAVA_PID" ] ; then
echo -e "[INFO] $HOST_NAME: stopping jboss ...\c"
$JBOSS_HOME/bin/jboss-cli.sh --connect controller=localhost:$NAMING_PORT command=:shutdown > /dev/null 2>&1
LOOPS=0
while [ $LOOPS -lt 30 ]; do
printProcess
kill -s 0 $JBOSS_JAVA_PID > /dev/null 2>&1
if [ $? -eq 1 ]; then
break
fi
let LOOPS=LOOPS+1
done
JBOSS_JAVA_PID=`get_jboss_pid`
if [ ! -z "$JBOSS_JAVA_PID" ] ; then
echo -e "[INFO] kill java process $JBOSS_JAVA_PID .\c"
kill -9 $JBOSS_JAVA_PID > /dev/null 2>&1
fi
success "Oook!"
else
warning "[WARN] $HOST_NAME: jboss not running, who care?"
fi
}
get_jboss_pid(){
STR=`ps -C java -f --width 1000 | grep "$JBOSS_BASE_DIR"|awk '{print $2}'`
echo $STR
}
get_tomcat_pid(){
STR=`ps -C java -f --width 1000 | grep "$TOMCAT_BASE_DIR"|awk '{print $2}'`
echo $STR
}
stop_tomcat(){
TOMCAT_JAVA_PID=`get_tomcat_pid`
if [ ! -z "$TOMCAT_JAVA_PID" ] ; then
success "start to remove service register from zookeeper: $REMOVE_URL"
curl -m 3 -s -o /dev/null "$REMOVE_URL"
sleep 3s
success "success to remove $LOCAL_IP"
#echo -e "$HOST_NAME: stopping tomcat ...\c"
#$SERVER_HOME/bin/catalina.sh stop > /dev/null 2>&1
#LOOPS=0
#while [ $LOOPS -lt 30 ]; do
#printProcess
#kill -s 0 $TOMCAT_JAVA_PID > /dev/null 2>&1
#if [ $? -eq 1 ]; then
#break
#fi
#let LOOPS=LOOPS+1
#done
#TOMCAT_JAVA_PID=`get_tomcat_pid`
#if [ ! -z "$TOMCAT_JAVA_PID" ] ; then
echo -e "[INFO] kill java process $TOMCAT_JAVA_PID .\c"
kill -9 $TOMCAT_JAVA_PID > /dev/null 2>&1
#fi
success "Oook!"
else
warning "[WARN] $HOST_NAME: tomcat not running, who care?"
fi
}
if [ $SERVER_TYPE = "jboss" ]; then
stop_jboss
fi
if [ $SERVER_TYPE = "tomcat" ]; then
stop_tomcat
fi