用shell脚本自动部署项目

用shell脚本自动部署项目

自己写了一个,再次用的话,直接copy

#!/bin/bash
#redeplory project
#create by huangdengji 2016-09-22 16:41:22

projectDir='/u01/tomcat7070/webapps/'
str=`ps -ef | grep tomcat7070`
pid=`echo $str | awk '{print $2}'`
echo 'tomcat7070 pid:'${pid}

[ -f /home/jhnet/ROOT.war ] || {
    echo '/home/jhnet/ROOT.war not exist'
    exit 1
}

kill -9 ${pid}
if [ $? -eq 0 ]
then
    echo "kill tomcat success!"
else
    echo "kill tomcat fail!"
fi

path='/gxt_bak/'$(date +%Y%m%d%H%M)

mkdir ${path}
if [ $? -eq 0 ]
then
    echo 'created dir:'${path}' success!'
else
    echo 'created dir:'${path}' fail!'
    exit 1
fi


mv ${projectDir}ROOT* ${path}
if [ $? -eq 0 ]
then
    echo 'project back to dir:'${path}' success!'
else
    echo 'project back to dir:'${path}' fail!'
    exit 1
fi

mv /home/jhnet/ROOT.war ${projectDir}
if [ $? -eq 0 ]
then
    echo 'deplory project to dir:'${projectDir}' success!'
else
    echo 'deplory project to dir:'${projectDir}' fail!'
    exit 1
fi

/u01/tomcat7070/bin/startup.sh
echo 'starting tomcat7070 ...'
tail -f /u01/tomcat7070/logs/catalina.out

相关推荐