加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
auto_distribution.sh 4.34 KB
一键复制 编辑 原始数据 按行查看 历史
operation_creator 提交于 2018-02-23 11:16 . upload project
#!/bin/bash
SERVICE_SVN_PATH=~/service_svn
SERVICE_CONFIG_PATH=~/service_config
SERVICE_RUN_PATH=~/service_run
PARAMS_LENGTH=$#
if [ $PARAMS_LENGTH -lt 1 ]; then
echo "at least need svn path param"
echo "the order should be like ./auto_distribution.sh svn_path uat|test|dev|production"
exit -1
fi
SVN_PATH_REG="^(svn://)"
SVN_PATH=$1
if [ -z $SVN_PATH ]; then
echo "needs svn path"
exit -1
fi
if [[ ! $SVN_PATH =~ $SVN_PATH_REG ]]; then
echo "svn path should be like svn://svn_path"
exit -1
fi
ENV=$2
if [ -z $ENV ]; then
ENV="dev"
fi
SERVICE_NAME=${SVN_PATH##*/}
PROJECT_SVN_PATH=$SERVICE_SVN_PATH/$SERVICE_NAME
if [ ! -e $PROJECT_SVN_PATH ]; then
echo "no such directory named $PROJECT_SVN_PATH"
exit -1
fi
PROJECT_CONFIG_PATH=$SERVICE_CONFIG_PATH/$SERVICE_NAME/$ENV
if [ ! -e $PROJECT_CONFIG_PATH ]; then
echo "no such directory named $PROJECT_CONFIG_PATH"
exit -1
fi
PROJECT_RUN_PATH=$SERVICE_RUN_PATH/$SERVICE_NAME
if [ ! -e $PROJECT_RUN_PATH ]; then
echo "no such directory named $PROJECT_RUN_PATH"
exit -1
fi
{
echo "start download $SERVICE_NAME from $SVN_PATH to $PROJECT_SVN_PATH..."
svn co $SVN_PATH $PROJECT_SVN_PATH
echo "download $SERVICE_NAME complete"
} || {
echo "download $SERVICE_NAME from $SVN_PATH failed"
exit -1
}
PROJECT_SVN_CONFIG_PATH=$PROJECT_SVN_PATH/src/main/resources
if [ ! -e $PROJECT_SVN_CONFIG_PATH ]; then
echo "no such directory named $PROJECT_SVN_CONFIG_PATH"
exit -1
fi
function cp_config_file(){
ORIGIN_CONFIG_FILE=$1
SVN_CONFIG_DIR=$2
if [ ! -e $ORIGIN_CONFIG_FILE -o -d $ORIGIN_CONFIG_FILE ]; then
echo "no such file named $ORIGIN_CONFIG_FILE"
echo "or $ORIGIN_CONFIG_FILE should be a file"
return -1
fi
if [ ! -e $SVN_CONFIG_DIR -o ! -d $SVN_CONFIG_DIR ]; then
echo "no such directory named $SVN_CONFIG_FILE"
echo "or $SVN_CONFIG_FILE should be a directory"
return -1
fi
for config_file in $SVN_CONFIG_DIR/*
do
if [ -d $config_file ]; then
cp_config_file $ORIGIN_CONFIG_FILE $config_file
else
if [ ${ORIGIN_CONFIG_FILE##*/} == ${config_file##*/} ]; then
echo "`cat $ORIGIN_CONFIG_FILE` to $config_file"
echo "`cat $ORIGIN_CONFIG_FILE`" > $config_file
fi
fi
done
return 0
}
function loop_config_file(){
ORIGIN_CONFIG_DIR=$1
if [ ! -e $ORIGIN_CONFIG_DIR -o ! -d $ORIGIN_CONFIG_DIR ]; then
echo "no such directory named $ORIGIN_CONFIG_DIR"
echo "or $ORIGIN_CONFIG_DIR should be a directory"
return -1
fi
for file in $ORIGIN_CONFIG_DIR/*
do
if [ -d $file ]; then
loop_config_file $file
else
cp_config_file $file $PROJECT_SVN_CONFIG_PATH
fi
done
return 0
}
loop_config_file $PROJECT_CONFIG_PATH
if [[ $? != 0 ]]; then
echo "update config file error"
exit -1
fi
{
echo "start compile $SERVICE_NAME using maven..."
cd $PROJECT_SVN_PATH
mvn install -Dmaven.test.skip=true
echo "compile $SERVICE_NAME complete"
} || {
echo "compile $SERVICE_NAME error"
exit -1
}
SVN_TARGET_PATH=$PROJECT_SVN_PATH/target
if [ ! -e $SVN_TARGET_PATH ]; then
echo "no such directory named $SVN_TARGET_PATH"
exit -1
fi
JAR_FILE_REG="(.jar)$"
JAR_RUN_FILE=""
for jar_file in $SVN_TARGET_PATH/*
do
if [ ! -d $jar_file ]; then
if [[ $jar_file =~ $JAR_FILE_REG ]]; then
JAR_RUN_FILE=$jar_file
echo "jar file is $JAR_RUN_FILE"
fi
fi
done
if [[ ! $JAR_RUN_FILE =~ $JAR_FILE_REG ]]; then
echo "jar file is not exist, compilation failed"
exit -1
else
echo "cp $JAR_RUN_FILE to $PROJECT_RUN_PATH"
cp $JAR_RUN_FILE $PROJECT_RUN_PATH
fi
FINAL_RUN_JAR=$PROJECT_RUN_PATH/${JAR_RUN_FILE##*/}
echo "final run jar file is $FINAL_RUN_JAR"
if [ ! -e $FINAL_RUN_JAR ]; then
echo "no such file named $FINAL_RUN_JAR"
exit -1
fi
AUTO_START=""
read -p "auto start service $SERVICE_NAME?(yes/no):" AUTO_START
case $AUTO_START in
yes)
(
SERVICE_PID=`jps -l | grep $SERVICE_NAME | awk '{printf $1}'`
PID_REG="^\d+$"
if [[ $SERVICE_PID =~ $PID_REG ]]; then
echo "$SERVICE_NAME pid is $SERVICE_PID"
echo "stop $SERVICE_NAME..."
kill 9 $SERVICE_PID
echo "$SERVICE_NAME stoped"
fi
) || {
echo "$SERVICE_NAME not run or stop failed"
echo "auto start failed"
exit 0
}
echo "starting service $SERVICE_NAME..."
cd $PROJECT_RUN_PATH
nohup java -Xms128m -Xmx128m -jar $FINAL_RUN_JAR > /dev/null &
echo "start service $SERVICE_NAME complete"
echo "please check out your log"
exit 0
;;
no)
exit 0
;;
*)
echo "input wrong word, the word should be yes/no"
exit 0
;;
esac
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化