This script is primarily used to manually publish war packages for non-MAVEN tomcat projects,
1. Upload the Test war package to the specified directory
2, back up the current production code
3. Automatic configuration file replacement
4, the release of the new version of the code
#!/bin/bash
########### #Setup Basic path and configuration file name #########################
Date= ' Date +%y%m%d '
Tomcat_home=/usr/local/kencery/tomcat
App_name=bqjr_fss
Backup_home=~/appbak
App_home= $tomcat _home/webapps/$app _name
Upload_war_home=/home/bqadm/deploy_directory
Declare-a config_file= (web-inf/classes/dbconfig.properties web-inf/classes/global.properties WEB-INF/classes/ Mq.properties web-inf/classes/sso.properties web-inf/classes/config.properties WEB-INF/classes/log4j.properties Web-inf/classes/quartz.properties web-inf/classes/uncheckedspxinfotemplate.xlsx)
#config_file主要用于配置需要替换的配置文件;
#################################################################################
Process_check () {
Count= ' Ps-ef |grep $ |grep-v "grep" |wc-l '
If [$count-eq 1];then
id= ' ps-ef|grep ' |grep-v ' grep ' |awk ' {p Rint "
Echo-e" is the Running,and PID is $id. \ n "
Elif [$count-eq 0]; then
Echo-e" are not running, Start later\n "
return"
Fi
}
Tomcat_stop () {
log_directory= ' pwd '
Echo-e "Start to stop tomcat:\n"
/bin/sh/$1/bin/shutdown.sh >> $log _directory/stop.log
I=0
While [' Ps-ef|grep $1|grep-v grep|wc-l '-eq 1]; Do
Echo-e ".......... ... \ n".... "
If [$ ($i + 1)-gt 3]; Then
echo "Stop Tomcat Failed,kill tomcat\n"
Pid= ' Ps-ef|grep $1|grep-v Grep|awk ' {print $} '
Kill-9 $PID
Break
Fi
Sleep 10
Done
If [' Ps-ef|grep $1|grep-v grep|wc-l '-eq 0]; Then
Echo-e "Success to stop ' basename $ ': \033[41;36m [OK] \033[0m\n"
Else
Echo-e "Failed to stop ' basename $ ': \033[41;36m [faild] \033[0m\n"
Fi
}
Tomcat_start () {
log_directory= ' pwd '
Echo-e "start to start tomcat:\n"
Echo-e ".......... ... \ n".... "
/bin/sh/$1/bin/startup.sh >> $log _directory/start.log
RM-RF $1/webapps/*
Cp-r $upload _war_home/$app _name.war $1/webapps/
J=0
While [' Ps-ef|grep $tomcat _home|grep-v grep|wc-l '-ne 1]; Do
If [$ ($j + 1)-gt 3]; Then
echo "Start failed,please check log\n";
Fi
Sleep 10
Done
If [' Ps-ef|grep $1|grep-v grep|wc-l '-eq 1]; Then
Echo-e "Success to start ' basename $ ': \033[41;36m [OK] \033[0m\n"
Else
Echo-e "Failed to start ' basename $ ': \033[41;36m [faild] \033[0m\n"; Exit 33
Fi
}
######### #Backup && War Package upload#############################################
If [-D $bak _$date/$app _name];then
Echo-e "backuped, No more backup.\n"
Else
Mkdir-p $backup _home/bak_$date
Scp-r $app _home $backup _home/bak_$date/
Ls-lsh $backup _home/bak_$date
Echo-e "Backup was did, Start to check War package.\n"
Fi
A=y
#read-P "Please ensure this war package have been uploaded: (y/n):" A
Cd..
CD $upload _war_home
if [$a = = ' Y ']; then
If [-f $app _name.war]; Then
ECHO-E "War package was uploaded. Would replace the configuration file.\n "
Else
Echo-e "No War Package,please upload the war package to $upload _war_home.\n"; Exit 0
Fi
Else
echo "Choice is NO. War package Hasnot been uploaded,please upload the war file to $upload _war_home. "; Exit 0
Fi
########## #Replace Configuration file#######################################################################
Echo-e "Start to replace Confige file"
Mkdir-p $upload _war_home
For Var in ${config_file[@]};
Do
CD $app _home
CP--parents $var $upload _war_home
Done
CD $upload _war_home
For Var in ${config_file[@]};
Do
JAR-UVF $app _name.war $var
Done
########### #Application deploy################################################################################# #
Process_check ' basename $tomcat _home '
If [$?-eq 41]; Then
Tomcat_start $tomcat _home
Else
Tomcat_stop $tomcat _home
Tomcat_start $tomcat _home
Fi
Shell implementation of war package configuration updates and automatic publishing