DIR=`dirname $0`
TOMCAT_DIR=/root/NetWorkFlow/apache-tomcat-8.5.16
WEBAPP_DIR=$TOMCAT_DIR/webapps
TMPDIR=/root/NetWorkFlow/tmp
JAVA_HOME=/lib/jvm/jdk1.8.0_131
echo "tomcat dir is ${TOMCAT_DIR}"
if [ $# -ne 1 ] ; then
echo ". deploy.sh "
exit 1
fi
APP_NAME=$1
APP_FILE=${APP_NAME}.war
TMPFILE_WAR=$TMPDIR/$APP_FILE
export JAVA_HOME
echo "Deploying file [$APP_file],TMPDIR is [$TMPDIR],DIR is [$DIR]"
if [ ! -f "$TMPFILE_WAR" ] ; then
echo "$TMPFILE_WAR is not exists"
exit 1
fi
echo "Remove old backup $TMPDIR/${APP_NAME}_bak"
rm -fr $TMPDIR/${APP_NAME}_bak
cd $TMPDIR
echo "Backup the old app"
mv $WEBAPP_DIR/$APP_NAME $TMPDIR/
mv $APP_NAME ${APP_NAME}_bak
echo "mv war to webapp"
cd $WEBAPP_DIR
mkdir $APP_NAME
cd $APP_NAME
mv $TMPDIR/$APP_FILE $WEBAPP_DIR/$APP_NAME/
unzip $APP_FILE
rm $APP_FILE
cd $TOMCAT_DIR/bin
echo "Stop server system"
#./shutdown.sh
#count=`ps -efc|grep tomcat|wc -l`
#killedNum=0
#echo "count pid num: ${count}"
#if [ $count -gt 1 ]; then
# PIDS=`ps -efc|grep tomcat|awk -F ‘ ‘ ‘{print $2}’`
# for PID in $PIDS
# do
# let killedNum++
# echo "kielledNum :${killedNum} pid ${PID}"
# if [ $count -gt $killedNum ]; then
# echo "kill current pid ${PID}"
# kill ${PID}
# fi
# done
#fi
set fileformat=unix
#force shutdown tomcat,copy this sh file to tomcat/bin dir
path=${DIR}
#path=/root/Middleware/apache-tomcat-7.0.28-system/bin/
ps -ef|grep $path|grep java|awk ‘{print $2}’
echo "exec ./shutdown.sh"
./shutdown.sh
sleep 3s
#kill -9 pid
ps -ef|grep $path|grep java|awk ‘{print $2}’|xargs kill -9
#success msg
echo "shutdown success"
ps -ef|grep $path|grep java|awk ‘{print $2}’
echo "Start server"
./startup.sh > /dev/null 2>&1
本文由【waitig】发表在等英博客 本文固定链接:jenkins自动部署tomcat脚本 欢迎关注本站官方公众号,每日都有干货分享!
点赞 (0)赏分享 (0)