开发环境tomcat下经常重新部署,需要关闭tomcat进程,判断是否关闭成功,配置文件替换,图片备份,再启动tomcat.
通过ps和awk命令,可以把关闭和启动tomcat命令都集成到一个脚本中,一键部署更新.
以下是一个真实列子:
app='/home/poc/tomcat'
info=`ps aux | grep "${app}" | grep -v grep|awk '{print $2}'`
if [ -z "$info" ]; then
echo 'is not running and start tomcat'
else
echo 'is also running and stopping'
/home/poc/tomcat/bin/shutdown.sh
sleep 1
info=`ps aux | grep "${app}" | grep -v grep|awk '{print $2}'`
if [ -z "$info" ]; then
echo 'start tomcat...'
else
kill -9 $info
echo 'kill tomcat'
fi
fi
cd /home/poc/tomcat/webapps
rm -rf /home/poc/identityPic
echo '备份图片'
cp /home/poc/tomcat/webapps/ar/identityPic ~ -R
rm -rf ar*
mkdir ar
cp ~/ar.war ar/
cd ar
rm -rf identityPic
jar xvf ar.war
rm -rf ar.war
cp ~/config/config.properties WEB-INF/classes/tinyConf
cp ~/config/db.properties WEB-INF/classes/tinyConf
cp /home/poc/identityPic /home/poc/tomcat/webapps/ar/ -R
echo 'start tomcat'
/home/poc/tomcat/bin/startup.sh