#!/bin/shweb
#使用監視模式,若是不設置該命令。可能致使經過shell腳本啓動之後,shell斷開鏈接,啓用的應用程序也會隨之中止。shell
set -m app
# 定義變量接收值, 如: ./test.sh gx test true truewebapp
provice="$1"
profile="$2"
if [ "${profile}" = "" ];then
profile="test"
fimaven
skip_core="$3"
skip_common="$4"svn
path=`pwd` spa
#`pwd`表明當前目錄。注意是`符號,而不是'單引號
PROJECT_NAME='lottery'
SUB_PROJECT_NAME='lottery-service'code
suffix=""
if [ "${provice}" != "gx" ];then
suffix="-${provice}"
fi
TC_PATH="/opt/tc-server/joywifi-server-${SUB_PROJECT_NAME}${suffix}"server
#從svn上更新代碼xml
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