# path
web_dir=/Users/abc/Desktop/war
web_tomcat_dir=/Users/abc/Downloads/apache-tomcat-8.0.36
# file
web_war_file=demo.war
# find all war
findAllWar(){
cd $web_dir
war_file_list=$(find $web_dir -name "*.war")
ls $war_file_list
}
# list
list(){
stepInfo "-------- search war file --------"
for i in $(findAllWar)
do
file_path=$i
#echo $file_path
file_name=${file_path##*/}
#echo $file_name
if [ $file_name = $web_war_file ]
then
echo $file_name
# param tips: $1 tomcat path $2 war name.war $3 war name
inTomcat $web_tomcat_dir $file_name $(basename $file_name .war)
fi
done
}
# cp file to tomcat
inTomcat(){
stepInfo "-------- file to Tomcat --------"
# To determine if a folder exists, if it exists, then it is skipped. Otherwise, it is building a folder.
stopTomcat $1
cd "$1/webapps"
if [ ! -x "$3" ]; then
echo "$1/webapps/$3 is not exists, it will be created!"
else
rm -rf $3
echo "$1/webapps/$3 is already exists, it will be deleted!"
fi
mkdir "$3"
echo "$1/webapps/$3 create success !"
cd $1/webapps/$3
jar -xvf $web_dir/$2
startTomcat $1
}
# stop tomcat
stopTomcat(){
stepInfo "-------- stop the Tomcat --------"
cd $1/bin
./shutdown.sh
rm -rf $1/logs/*
rm -rf $1/work/*
echo "rm logs/* & work/*....."
}
# start tomcat
startTomcat(){
stepInfo "-------- start the Tomcat --------"
cd $1/bin
./startup.sh
tail -f $1/logs/catalina.out
}
# echo step info
stepInfo(){
echo " "
echo "$1"
echo " "
}
list