Tomcat 自动化部署脚本
使用方法: ./autodeploy.sh test
其中autodeploy.sh 为脚本的文件名, test为war的文件名。
#!/bin/sh now=`date +%Y%m%d%H%M%S` echo $now tomcat_path="/home/larry/tomcat8.0.45" backup_path="/home/larry/tomcat8.0.45/backup" war=$1 if [ -e $1.war ]; then echo -e "\033[34m war achive : '$1.war' exists \033[0m" else echo -e "\033[31m war achive : $1.war not exists \033[0m" exit fi #change color echo -e "\033[34m" #create backup dir if [ ! -d "$backup_path" ]; then mkdir "$backup_path" fi echo "tomcat home: $tomcat_path" echo "backup path: $backup_path" echo 'try to stop tomcat...' pid=`ps aux|grep "java" | grep "$tomcat_path" | awk '{printf $2}'` if [ -n $pid ]; then echo "tomcat pid: $pid"; kill -9 $pid; fi echo 'stop tomcat finished...' echo 'back old archive...' echo $tomcat_path/webapps/$war.war if [ -f "$tomcat_path/webapps/$war.war" ]; then mv -v "$tomcat_path/webapps/$war.war" "$backup_path/$1_$now.war"; fi rm -rf $tomcat_path/webapps/$war* echo "copy $war.war archive to webapps.." cp -v "$war.war" "$tomcat_path/webapps/" echo -e "\033[32m" echo 'startup tomcat...' sh $tomcat_path/bin/startup.sh tail -10f $tomcat_path/logs/catalina.out
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!