2019独角兽企业重金招聘Python工程师标准>>>
#!/bin/sh
#使用监视模式,如果不设置该命令。可能导致通过shell脚本启动以后,shell断开连接,启用的应用程序也会随之停止。
set -m
# 定义变量接收值, 如: ./test.sh gx test true true
provice="$1"
profile="$2"
if [ "${profile}" = "" ];then
profile="test"
fi
skip_core="$3"
skip_common="$4"
path=`pwd`
#`pwd`代表当前目录。注意是`符号,而不是'单引号
PROJECT_NAME='lottery'
SUB_PROJECT_NAME='lottery-service'
suffix=""
if [ "${provice}" != "gx" ];then
suffix="-${provice}"
fi
TC_PATH="/opt/tc-server/joywifi-server-${SUB_PROJECT_NAME}${suffix}"
#从svn上更新代码
update_code(){
if [ -e $PROJECT_NAME ];then
cd $PROJECT_NAME && svn update --username "xuebin.yang" --password "888888"
else
svn checkout "http://10.13.0.55:8080/svn/GL_SCLT/trunk/${PROJECT_NAME}" --username "xuebin.yang" --password "888888"
fi
}
#进行打包处理
package(){
cd ${path}/${PROJECT_NAME}
if [ "$skip_core" != "true" ];then
echo 'install lottery-core'
mvn clean install -f lottery-core/pom.xml -P ${provice} -Dmaven.test.skip=true
fi
if [ "$skip_common" != "true" ];then
echo 'install lottery-common'
mvn clean install -f lottery-common/pom.xml -P ${provice} -Dmaven.test.skip=true
fi
echo "package ${SUB_PROJECT_NAME}"
mvn clean package -P ${profile}-${provice} -Dmaven.test.skip=true -f ${SUB_PROJECT_NAME}/pom.xml
if [ $? -ne 0 ];then
echo '打包不成功,请检查svn代码'
exit 0
fi
}
#mvn命令部署项目
deploy(){
${TC_PATH}/bin/tcruntime-ctl.sh stop
rm -rf ${TC_PATH}/webapps/ROOT/
rm -rf ${TC_PATH}/webapps/ROOT.war.BAK
mv ${TC_PATH}/webapps/ROOT.war ${TC_PATH}/webapps/ROOT.war.BAK
cp ${path}/${PROJECT_NAME}/${SUB_PROJECT_NAME}/target/ROOT-${profile}.war ${TC_PATH}/webapps/ROOT.war
${TC_PATH}/bin/tcruntime-ctl.sh start &
tail -f ${TC_PATH}/logs/catalina.out
}
if [ $path != '/home/sh-command/deploy' ];then
echo '请到/home/sh-command/deploy目录下运行'
exit 0
fi
if [ $# -lt 1 ];then
echo "请输入省份"
exit 0
fi
update_code
package
read -p '是否部署?Y/N' is_deploy
echo "是否部署:$is_deploy"
if [ $is_deploy = "y" ] || [ $is_deploy = "yes" ];then
deploy
elif [ $is_deploy = "n" ] || [ $is_deploy = "no" ];then
echo -e "\033[31m 取消部署 \033[0m"
else
while [ $is_deploy != "y" ] || [ $is_deploy != "yes" ] || [ $is_deploy != "n" ] || [ $is_deploy != "no" ];do
read -p '是否部署?Y/N' is_deploy
echo "是否部署:$is_deploy"
if [ $is_deploy = "y" ] || [ $is_deploy = "yes" ];then
deploy
break
elif [ $is_deploy = "n" ] || [ $is_deploy = "no" ];then
echo -e "\033[31m 取消部署 \033[0m"
break
fi
done
fi