需要在/tomcat/source/release/目录下存在app_list.txt文件,文件内容为换行填写的服务模块名:
restart_server_jdk1.8.0_121.sh
#!/bin/sh
export LANG=en_US.UTF-8
export JAVA_HOME=/usr/java/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
war_path=/tomcat/source/release
if [ ! -d "$war_path" ]; then
mkdir $war_path
fi
cd $war_path
app_count=`cat app_list.txt |wc -l`
stdep(){
DIR=/tomcat/$1
echo "Shutdown the" $1 "service"
cd $DIR/bin
sh $DIR/bin/catalina.sh stop
sleep 15
kill -9 `ps aux|grep java |grep "/tomcat/$1/" |grep -v grep |gawk '{print $2}'`
echo $1 "Service stop waiting for 20 seconds"
sleep 2
echo "clearing the" $1 "cache"
rm $DIR/work/Catalina -rf
rm $DIR/webapps/$1 -rf
sleep 5
sh $DIR/bin/startup.sh
sleep 5
for (( c=1; c<=6; c++ ))
do
# Check tomcat instance running status
tail -n200 $DIR/logs/catalina.out |grep -q "Server startup"
if [ $? != 0 ]; then
echo $1 "Service start is slow, please wait for 10 seconds"
sleep 10
else
echo "- - - The service is started successfully - - - "
break
fi
done
SERVER_PORT=`grep port $DIR/conf/server.xml |grep tomcatThreadPool|awk -F " " '{print $3}'|cut -c7-10`
echo "http://localhost:$SERVER_PORT/$1/echo"
echo "--------Application status --------"
curl http://localhost:$SERVER_PORT/$1/echo
echo -e "\n"
}
if [ $app_count -eq 0 ];then
echo -n "No wars!"
else
for((i=1;i<=$app_count;i++))
do
name=`cat app_list.txt |sed -n "$i"p`
stdep $name
cd $war_path
done
fi