tomcat发布脚本

#!/bin/bash

#发布相关目录
Tomcat_log='/home/CodePub/tomcatlog'
dev_package='/home/CodePub/package'
old_package='/home/CodePub/oldpackage'
tomcat_dir='/home/zoumi/youximao/tomcat' #修改
tomcat_start_dir='/home/zoumi/youximao/tomcat/bin' #修改
Mysqllog='/home/CodePub/mysqllogs'
Mysqlbackup='/home/CodePub/Mysqlbackup'

cd /home #可能需要更改
if [ -d CodePub ];then
if [ ! -d tomcatlog ]
then
mkdir tomcatlog
chmod 775 tomcatlog
fi

if [ ! -d package ]
then
mkdir package
chmod 775 package
fi

if [ ! -d oldpackage ]
then
mkdir oldpackage
chmod 775
fi

if [ ! -d mysqllogs ]
then
mkdir mysqllogs
chmod 775 mysqllogs
fi
else
mkdir CodePub
chmod 775 CodePub
cd /home/CodePub #可能需要更改
mkdir tomcatlog package oldpackage mysqllogs
chmod 775 tomcatlog package oldpackage mysqllogs
fi

#用户需要修改的参数 数据库连接参数
User='root'
Port='3306'
Passwd='123456'
Time="$(date +"%Y%m%d%H%M%S")"

echo "please input update or return"
echo "update input 1"
echo "return input 2"
read -p "please input release type :" type

update(){
$tomcat_start_dir/shutdown.sh &> /dev/null;sleep 5
process="$(ps aux | grep tomcat | grep "$tomcat_start_dir" | awk '{print $2}')"
for ps in $process
do
if [ -n "$ps" ];then
kill -9 $ps
fi
done
redis="$(ps aux | grep redis | grep "/usr/local/bin/" | awk '{print $2}')"
for RD in $redis
do
kill -9 $RD
done

cd $tomcat_dir
tar -zcpvPf $old_package/$Time.tar.gz $tomcat_dir/webapps/* >> $Tomcat_log/tomcat-tar-$Time.log
echo "Input new develop package"
read -p "please input package_name:" package_name
echo "Input new database script"
read -p "please input script_name:" script_name
if [ -n "$script_name" ]
then
echo "----------开始执行数据库脚本文件----------"
mysql -u $User -P $Port -p$Passwd -Bse 'source /home/zoumi/'$script_name'' > $Mysqllog/mysql-$Time.log
echo "-----------截取Tomcat启动日志50S-----------"
fi
yes | cp -fr /home/zoumi/$package_name $tomcat_dir/webapps/ #发布包目录位置,可能需要修改
$tomcat_start_dir/startup.sh
tail -f $tomcat_dir/logs/catalina.out > $Tomcat_log/tomcat-up-$Time.log &
sleep 50
taps="$(ps aux | grep tail | grep "$tomcat_dir/logs/catalina.out" | awk '{print $2}')"
if [ -n "$taps" ];then
kill -9 $taps
fi

/usr/local/bin/redis-server --port 6379 &
/usr/local/bin/redis-server --port 8888 &
# cat $Tomcat_log/tomcat-up-$Time.log | grep "error"
}

Return(){
$tomcat_start_dir/shutdown.sh &> /dev/null
read -p "please input this yasuo oldpackage" ago_package
tar -zxPf $old_package/$ago_package -C /home/zoumi/youximao/tomcat/webapps/
/home/zoumi/youximao/tomcat/bin/startup.sh >> /home/tomcat-oldup-$Time.log
cat $Tomcat_log/tomcat-oldup-$Time.log | grep "error"
}

case "$type" in
"1")
update
;;

"2")
Return
;;

*)
echo "Input error!"
esac
exit 0

上一篇:Web API 接口


下一篇:Winform混合式开发框架访问Web API接口的处理