#!/bin/bash
# added by royoy
# July 10/2019
# reset for services
service_dir="/home/ubuntu/deploy/services"
deploy_dir="/home/ubuntu/deploy"
repos_dir="/home/ubuntu/repos"
if [ $# -eq 0 ];then "Args is required";exit;fi
test $2 && reset_version="$2" || reset_version="HEAD~1"
##首先确保在master分支上
if ! cd ${service_dir} >/dev/null 2>&1;then echo "不能进入${service_dir}目录,退出本次回滚";exit 31;fi
git checkout master || {
echo "checkout master failed"
exit
}
##执行回滚操作
git reset --hard ${reset_version}
##拷贝代码到待发布目录
if [ $? -ne 0 ];then echo "回滚失败";exit;fi
if ! cd ${deploy_dir} >/dev/null 2>&1;then echo "不能进入${deploy_dir}目录,退出本次拷贝";exit 32;fi
make services || {
echo "make services failed"
exit
}
wait
sleep 9
##发布配置文件和代码
if ! cd "$repos_dir" >/dev/null 2>&1;then echo "不能进入${repos_dir}目录,退出本次发布";exit 33;fi
make services && make workers && make workers-reload