Shell如下:

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
#!/bin/bash  
#defined
export JAVA_HOME=/root/.jenkins/tools/hudson.model.JDK/jdk8
NUM="$1"
TOMCAT_HOME="/opt/soft/tomcat_cluster/tomcat_$NUM"

if [ $NUM = 1 ]
then
TOMCAT_PORT=8090
fi

if [ $NUM = 2 ]
then
TOMCAT_PORT=8100
fi

if [ $NUM = 3 ]
then
TOMCAT_PORT=8110
fi

if [ $NUM = 0 ]
then
TOMCAT_PORT=8060
fi
#shutdown tomcat
#"$TOMCAT_HOME"/bin/shutdown.sh
#echo "tomcat shutdown"
#check tomcat process
tomcat_pid=`/usr/sbin/lsof -n -P -t -i :$TOMCAT_PORT`
echo "current :" $tomcat_pid
while [ -n "$tomcat_pid" ]
do
sleep 5
tomcat_pid=`/usr/sbin/lsof -n -P -t -i :$TOMCAT_PORT`
echo "scan tomcat pid :" $tomcat_pid
if [ -n "$tomcat_pid" ]; then
echo "kill tomcat :" $tomcat_pid
kill -9 $tomcat_pid
fi
done
#start tomcat
cd "$TOMCAT_HOME"
./bin/startup.sh

更多文章,请关注:开猿笔记