结合jenkins做发布tomcat项目

#!/bin/bash
source /etc/profile
source /etc/init.d/functions
###
bak_war=”/opt/backup_war/monitor”
monitor_path=”/opt/tomcat8_monitor/webapps/”
monitor_war=”/opt/upload_war”
###
monitor_line=`ps -ef |grep monitor |grep -v grep|wc -l`
now=`date +%Y-%m-%d-%H-%M_`

function start_tomcat(){
/usr/bin/sh /opt/tomcat8_monitor/bin/startup.sh
}
function restart_tomcat(){
ps -ef |grep monitor |grep -v grep|awk -F ” ” ‘{print $2}’ |xargs kill -9
cd $monitor_path && tar -zcvf $bak_war/ROOT_$now.tgz ROOT/
rm -rf $monitor_path/ROOT/*
cd $monitor_war && unzip monitor-web.war -d $monitor_path/ROOT/
/usr/bin/sh /opt/tomcat8_monitor/bin/startup.sh
}

if [ $monitor_line -eq 0 ];
then
start_tomcat
else
restart_tomcat
fi
if [ $monitor_line -eq 1 ];
then
restart_tomcat
fi

发表评论