生产文件部署脚本
一、生产文件部署(更新文件)脚本
# cat replace-papers.sh
#!/bin/bash
# Author: miclesvic(LGH)
# Date: 2015-09-21
# Mail: liugohui@silupay.com
# 功 能:替换|回滚B2C项目文件脚本
# 使用方法:1. 将需要替换的文件上传到/home/bak_up/update/,并找到该文件所在项目对应路径并写在如下文件中:
# /root/scripts/all-file.functions
# 并以以下形式写在该文件中,例:
# /data/tomcat1/webapps/ROOT/admin/ index.jsp
# /data/tomcat1/webapps/ROOT/upload/image/ watermark.png
# 2. 执行该脚本,例:/root/scripts/exchange-file.sh
# 替换|回滚 1|2 :
# 3. 可选择相应的选项,1 为替换文件,2 为回滚文件;
# 郑重提示:脚本执行后备份文件均备份在文件所在的同一目录下,并以文件名和时间命名。
# -------------------------------- 函 数 --------------------------
. /etc/init.d/functions
Tomcat_App_D=/data/tomcat1/webapps
DATE_old=`date +%Y-%m-%d-%H-%M-%S`
Up_dir=/home/bak_up/update
# -------------------------tomcat_start 开启服务-------------------
function tomcat_start () {
cd ${Tomcat_App_D}
chown -R slts.slts ROOT
chmod -R 755 ROOT
Tomcat_Status=`ps -ef | grep tomcat1 | grep -v grep | awk '{print $2}'|wc -l`
if [ ${Tomcat_Status} -eq 1 ];then
echo "Tomcat1 Service is running."
else
su - slts -c "/data/tomcat1/bin/catalina.sh start" > /dev/null 2>&1
action "Tomcat1 Service start seccess" /bin/true
fi
}
# -------------------tomcat_stop 停止服务--------------------
function tomcat_stop () {
ps -ef | grep tomcat1 | grep -v grep | awk '{print $2}'| xargs kill -9
Tomcat_Status=`ps -ef | grep tomcat1 | grep -v grep | awk '{print $2}'|wc -l`
if [ ${Tomcat_Status} -eq 0 ];then
action "Tomcat1 Service stop success" /bin/true
else
action "Tomcat1 Service is stoped" /bin/false
fi
}
# ------------tomcat_exchange 文件替换------------------------
function tomcat_exchange () {
tomcat_stop
while read upfile
do
dir=$(echo $upfile| awk '{print $1}')
file=$(echo $upfile| awk '{print $2}')
cd $dir
if [ -f $file ];then
echo "$file 文件存在"
if [ -f $file.bak ];then
mv $file $file-${DATE_old}.bak
else
mv $file $file.bak
fi
else
echo "$file 文件不存在"
fi
mv $Up_dir/$file $dir
action "$file 替换文件成功" /bin/true
done < /root/scripts/all-file.functions
sleep 3
tomcat_start
}
# ----------tomcat_roback 回滚--------------------
function tomcat_roback () {
tomcat_stop
while read roback
do
dir=$(echo $roback| awk '{print $1}')
file=$(echo $roback| awk '{print $2}')
cd $dir
if [ -f $file.bak ];then
mv ${file}.bak $file
else
echo "${file}.bak 文件不存在"
mv ${file} ${file}.add-file
fi
action "$file 回滚成功" /bin/true
done < /root/scripts/all-file.functions
sleep 3
tomcat_start
}
# ---------------函数选择------------------------------------------
read -p "替换|回滚 1|2 :" i
case $i in
1)
tomcat_exchange
;;
2)
tomcat_roback
;;
esac
# --------------------------------------------------------
二、更新文件列表文件
# cat all-file.functions /data/tomcat1/webapps/ROOT/WEB-INF/classes/net/silugo/service/impl MemberServiceImpl.class /data/tomcat1/webapps/ROOT/WEB-INF/template/m login.ftl

浙公网安备 33010602011771号