#!/bin/bash
DAT=`date +%F` # 所有的变量中必须放在第一位
PATH="/usr/local/crm.server"
BACKUP_PATH="/root/pkgs/bakcup"
REPLIC_PATH="/tmp/temp"
REMOTE_HOST="10.205.2.x"
TEMP_PATH="/root/tmp"
# 判断执行返回结果
Execution_result(){
local method_name="$1"
local right_message="$2"
local error_message="$3"
if [[ $? -eq 0 ]]; then
echo "${method_name}" "${right_message}"
else
echo "${method_name}" "${error_message}"
exit 1
fi
}
# 备份项目
Backup_program(){
local program_name="backup_program"
local msg_or_rc=$1
cd "${PATH}"/"${msg_or_rc}"
/usr/bin/zip -rq "${BACKUP_PATH}"/"${msg_or_rc}"/webapps_$DAT.zip webapps/
if [[ ! -f "${BACKUP_PATH}"/"${msg_or_rc}"/webapps_$DAT.zip ]]; then
echo "$program_name $msg_or_rc failed"
exit 1
else
echo "$program_name $msg_or_rc success."
fi
}
# 从远端复制最新代码到临时目录
Replicate_program(){
local program_name="Replicate_program"
local msg_or_rc=$1
/usr/bin/scp -rq "${REMOTE_HOST}":"${PATH}"/"${msg_or_rc}"/webapps "${REPLIC_PATH}"/"${msg_or_rc}"
Execution_result "${program_name}" "scp program from $REMOTE_HOST success." "scp program from $REMOTE_HOST failed."
}
# 停止Tomcat服务
Stop_tomcat(){
local program_name="stop_tomcat"
local msg_or_rc=$1
is_actived=`ps -ef | grep "$PATH/$msg_or_rc" | grep -v grep`
if [[ -n "${is_actived}" ]]; then
ps -ef | grep "$PATH/$msg_or_rc" | grep -v grep | awk '{print $2}' | xargs kill -9
sleep 3
is_actived=`ps -ef | grep "$PATH/$msg_or_rc" | grep -v grep`
if [[ -n "${is_actived}" ]]; then
echo "$program_name $msg_or_rc stop failed."
exit 1
else
Execution_result "$program_name" " stop $msg_or_rc success." "stop $msg_or_rc failed"
fi
else
echo "Service $msg_or_rc has been stopped before kill."
fi
}
# 启动Tomcat服务
Start_tomcat(){
local program_name="start_tomcat"
local msg_or_rc=$1
/bin/bash "${PATH}"/"${msg_or_rc}"/bin/startup.sh
Execution_result "$program_name" "start $msg_or_rc success." "start $msg_or_rc failed."
}
# 替换项目文件
Replace_program(){
local program_name="Replace_program"
local msg_or_rc=$1
if [[ -d "${TEMP_PATH}"/$DAT ]]; then
mv "${PATH}"/"${msg_or_rc}"/webapps "${TEMP_PATH}"/$DAT/"${msg_or_rc}"-webapps
Execution_result "$program_name" "remove old program packages to temp path success"
else
mkdir "${TEMP_PATH}"/$DAT
mv "${PATH}"/"${msg_or_rc}"/webapps "${TEMP_PATH}"/$DAT/"${msg_or_rc}"-webapps
Execution_result "$program_name" "remove old program packages to temp path success"
fi
mv "${REPLIC_PATH}"/"${msg_or_rc}"/webapps "${PATH}"/"${msg_or_rc}"
Execution_result "$program_name" "remove new program packages to temp path success"
}
All(){
msg_or_rc=$1
Backup_program "${msg_or_rc}"
Replicate_program "${msg_or_rc}"
Stop_tomcat "${msg_or_rc}"
Replace_program "${msg_or_rc}"
Start_tomcat "${msg_or_rc}"
}
main(){
case $1 in
cca )
All cca;
;;
crms )
All crms;
;;
rqa )
All rqa;
;;
spm )
All spm;
;;
task )
All task;
;;
web )
All web;
;;
workflow )
All workflow;
;;
*)
echo $"Usage: $0 {cca | crms | rqa | spm | task | web | workflow}"
esac
}
main $1
自动化发布
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 一. 前提条件 服务器是Linux的 安装了Fabric 安装指导 安装了svn 安装指导 二. 整体思路 从sv...
- Fabric是一个Python(2.5~2.7)类库和命令行工具。官网的对该程序的定位是:Pythonic rem...