自动部署项目脚本参考:
#!/bin/bash
#自动部署脚本
source /etc/profile
export LANG=zh_CN.UTF-8
#tomcat路径
tomcatBinPath=/usr/local/apache-tomcat-8.5.43/bin
#war包和脚本目录
homepath=/home/ldc/tomcat_project/
echo '--------开始部署--------'
#检查war包是否存在
cd $homepath
if [ $(find ./ -maxdepth 1 -name "*.war"|wc -l) -ne 1 ]; then
echo '请保证/home/ldc/tomcat_project文件中有且只有一个war包!'
exit 1
fi
#Name=$(find ./ -maxdepth 1 -name "*.war"|awk -F '/' '{print $2}'|awk -F '.' '{print $1}')
#进入tomcat目录
cd $tomcatBinPath
if [ $? -ne 0 ];then
echo '请检查tomcat的bin路径是否正确!'
exit 1
fi
echo "进入tomcat的bin目录:$tomcatBinPath"
./shutdown.sh #停止tomcat服务
echo '成功关闭tomcat服务!'
cd $tomcatBinPath/../webapps/
if [ $? -ne 0 ];then
echo '请检查webapps路径是否正确!'
exit 1
fi
echo "进入webapps目录:$(pwd)"
rm -rf ./ROOT
unzip $homepath/*.war -d ROOT/
echo '解压完毕等待睡眠5s'
sleep 5
rm -rf $homepath/*
cd $tomcatBinPath
./startup.sh
echo '--------部署结束--------'
项目tomcat启动脚本
#!/bin/bash
source /etc/profile
export LANG=zh_CN.UTF-8
START=/usr/local/apache-tomcat-8.5.43/bin/startup.sh
STOP=/usr/local/apache-tomcat-8.5.43/bin/shutdown.sh
PID=$(ps -ef |grep 'org.apache.catalina.startup.Bootstrap' |grep -v grep|awk '{print $2}')
start()
{
echo $PID
if [ "$PID" ]
then
echo "tomcat已经启动!"
else $START
echo "tomcat启动成功!"
fi
}
stop()
{
if [ "$PID" ]
then
$STOP
kill -9 $PID
echo "tomcat已经关闭!"
PID=$(ps -ef |grep 'org.apache.catalina.startup.Bootstrap' |grep -v grep|awk '{print $2}')
else
echo "tomcat未启动!"
fi
}
restart()
{
if [ "$PID" ]
then
stop
fi
start
}
case $1 in
"start") start
;;
"stop") stop
;;
"restart") restart
;;*) echo "请输入正确的操作参数start|stop|restart"
;;
esac
--------------结束----------------------