1. 程式人生 > >linux下使用shell更新Tomcat下的war包

linux下使用shell更新Tomcat下的war包

#!/bin/sh
#check war exists
echo "check war exists"
war_file_path=/usr/tomcat/tomcat8.0_8090/webapps
war_file_name=CTIM.war


if [ ! -f "$war_file_path/$war_file_name" ]; then
echo " ------------war not exists----------"
exit
else
echo "-----------exists-------------"
fi


#check tomcat is running
echo "check tomcat is running if stop"
app_start_path=/usr/tomcat/tomcat8.0_8090/bin
app_start_name=startup.sh


#start tomcat
#sh $app_start_path/$app_start_name


pid_keyword=tomcat
pid=`ps -ef|grep $pid_keyword|grep -v grep|awk '{print $2}'`
echo "tomcat pid is:" $pid


if [ -n "$pid" ]; then
echo "the pid:'$pid' is stopping......"
kill -9 $pid
fi


#backup file
echo "backup war file start..."
echo "1.delete old backup file"
old_war_file_path=/usr/tomcat/tomcat8.0_8090/webapps
old_war_file_name=CTIM.war.bak


if [ -f "$old_war_file_path/$old_war_file_name" ]; then
echo "war.bak exists so delete it"
rm -f $old_war_file_path/$old_war_file_name
else
echo "war.bak not exists"
fi


echo "2.backup war file"
mv $war_file_path/$war_file_name $old_war_file_path/$old_war_file_name


echo "3.copy new war here "
new_war_file_path=/usr/tomcat
new_war_file_name=CTIM.war


if [ -f "$new_war_file_path/$new_war_file_name" ]; then
cp $new_war_file_path/$new_war_file_name $war_file_path
else
echo "new war file not esists"
exist
fi


#start tomcat
echo "tomcat start"
sh $app_start_path/$app_start_name