Bläddra i källkod

initial commit

krrish 7 år sedan
incheckning
6fef6ca190
5 ändrade filer med 763 tillägg och 0 borttagningar
  1. 38 0
      Dockerfile.tpl
  2. 193 0
      build/build_images.sh
  3. 189 0
      deploy/deploy_powercloud_latest.sh
  4. 196 0
      deploy/deploy_wisecloud_latest.sh
  5. 147 0
      docker/start.sh

+ 38 - 0
Dockerfile.tpl

@@ -0,0 +1,38 @@
+######## Dockerfile来源
+FROM registry.sviyun.com/os/svi-centos7:v1.2 
+
+######## 编写Dockerfiler人员邮箱
+MAINTAINER your_name <your_email@gmail.com>
+
+######## 网元相关变量
+ENV APP_HOME /opt/wisecloud/dcmp
+ENV APP_NAME dcmp_server 
+
+######## 自定义变量,没有可以不用写
+ENV JETTY_HOME ${APP_HOME}/${APP_NAME}/jetty9
+ENV JETTY_RUN ${JETTY_HOME}/bin
+
+######## 定义服务等待依赖
+#   1、支持协议(file, tcp, tcp4, tcp6, http, https and unix)
+#   3、变量值必须包含协议类型,服务域名,端口
+#   2、实例说明:表示当前Dockerfile启动需要依赖数据库和authcenter的web服务。
+ENV APP_DEP1 "tcp://postgres.postgres:5432"
+ENV APP_DEP2 "http://web.authcenter:80"
+
+######## 以下内容无需编辑修改
+ADD *.tar.gz /tmp
+RUN cd /tmp/*_release && \
+    cp -f docker/*.sh /usr/local/bin/ && \
+    chmod a+x /usr/local/bin/*.sh && \
+    cp -r docker/conf /usr/local/conf && \
+    touch /var/log/${APP_NAME}.log && \
+    # setup app
+    sh setup.sh && \
+    cd ~ && \
+    rm -rf /tmp/*_release
+    
+WORKDIR ${APP_HOME}/${APP_NAME}
+
+ENTRYPOINT ["tini", "--"]
+
+CMD ["start.sh"]

+ 193 - 0
build/build_images.sh

@@ -0,0 +1,193 @@
+#!/bin/bash
+
+FTP_DATA=/data/ftp
+
+#PROJECT_NAME=wisecloud
+MIRROR_ADDRESS="registry.sviyun.com"
+GIT_ADDRESS="git@git.svicloud.com:svicloud/wisecloud.git"
+
+anynowtime="date +'%Y-%m-%d %H:%M:%S'"
+NOW="echo [\`$anynowtime\`][PID:$$]"
+
+function tms_start
+{
+    echo "`eval $NOW` tms_start" >>"${BUILD_LOG}"
+}
+
+function tms_success
+{
+    msg="$*"
+    echo "`eval $NOW` tms_success:[$msg]" >>"${BUILD_LOG}"
+    echo "`eval $NOW` tms_success:[$msg]"
+    return 0
+}
+
+function tms_fail
+{
+
+    msg="$*"
+    echo "`eval $NOW` tms_fail:[$msg]" >>"${BUILD_LOG}"
+    echo "`eval $NOW` tms_fail:[$msg]"
+    return 1
+}
+
+
+function fn_print_err()
+{
+
+    local info_error=$1
+
+    echo "====================================================================================================" >>"${BUILD_LOG}"
+    cat "${ERROR_LOG}" >>"${BUILD_LOG}"
+    echo "====================================================================================================" >>"${BUILD_LOG}"
+
+    tms_fail "${info_error}" || return $?
+
+}
+
+
+function fn_build_images()
+{
+
+    local images_name=$1
+
+    #build new images
+    docker build -t "${MIRROR_ADDRESS}"/"${PROJECT_NAME}"/"${WANGYUAN_NAME}"/"${images_name}":"${IMAGE_VERSION}" . >"${ERROR_LOG}" 2>&1
+    if [ $? -ne 0 ]
+    then
+        fn_print_err "Build <${MIRROR_ADDRESS}/${PROJECT_NAME}/${WANGYUAN_NAME}/${images_name}:${IMAGE_VERSION}> failure." || return $?
+    fi
+
+    #tag images latest
+    docker tag "${MIRROR_ADDRESS}"/"${PROJECT_NAME}"/"${WANGYUAN_NAME}"/"${images_name}":"${IMAGE_VERSION}" "${MIRROR_ADDRESS}"/"${PROJECT_NAME}"/"${WANGYUAN_NAME}"/"${images_name}":latest  >"${ERROR_LOG}" 2>&1
+    if [ $? -ne 0 ]
+    then
+        fn_print_err "Tag <${MIRROR_ADDRESS}/${PROJECT_NAME}/${WANGYUAN_NAME}/${images_name}:latest> failure." || return $?
+    fi
+
+    #push images
+    docker push "${MIRROR_ADDRESS}"/"${PROJECT_NAME}"/"${WANGYUAN_NAME}"/"${images_name}":"${IMAGE_VERSION}" >"${ERROR_LOG}" 2>&1
+    if [ $? -ne 0 ]
+    then
+        fn_print_err "Push<${MIRROR_ADDRESS}/${PROJECT_NAME}/${WANGYUAN_NAME}/${images_name}:${IMAGE_VERSION}> failure." || return $?
+    fi
+
+    #push images latest
+    docker push "${MIRROR_ADDRESS}"/"${PROJECT_NAME}"/"${WANGYUAN_NAME}"/"${images_name}":"latest" >"${ERROR_LOG}" 2>&1
+    if [ $? -ne 0 ]
+    then
+        fn_print_err "Push<${MIRROR_ADDRESS}/${PROJECT_NAME}/${WANGYUAN_NAME}/${images_name}:latest> failure." || return $?
+    fi
+
+    return 0
+
+}
+
+
+function fn_version_json()
+{
+
+    local new_version
+
+    [ -d /tmp/wisecloud ] && rm -rf /tmp/wisecloud
+
+    cd /tmp
+    git clone "${GIT_ADDRESS}" >"${ERROR_LOG}" 2>&1
+    if [ $? -ne 0 ]
+    then
+        fn_print_err "Git <wisecloud.git> failure." || return $?
+    fi
+
+    cd /tmp/wisecloud && cp version.json version.backup
+
+    jq ".${WANGYUAN_NAME}.${MODULE_SERVICE_NAME}_version = \"${MODULE_SERVICE_VERSION}\"" version.backup >version.json
+    new_version=`jq ".${WANGYUAN_NAME}.${MODULE_SERVICE_NAME}_version" version.json |xargs`
+    if [ "${new_version}" != "${MODULE_SERVICE_VERSION}" ]
+    then
+        fn_print_err "Version upgrade ${MODULE_SERVICE_VERSION} failed" || return $?
+    else
+    rm version.backup
+    fi
+
+    git add version.json  || return $?
+    git commit -m "${MODULE_SERVICE_VERSION}"
+    git push || return $?
+
+    tms_success "Version upgrade ${MODULE_SERVICE_VERSION} finish."
+    return 0
+
+}
+
+
+fn_main()
+{
+
+    MODUL_NAME=$1
+    local svn_number=$2
+    PROJECT_NAME=$3
+    
+    #定义日志打印的路径
+    BUILD_LOG=/tmp/${MODUL_NAME}/build.log
+    ERROR_LOG=/tmp/${MODUL_NAME}/error.log
+    
+    #创建日志文件
+    [ -d /tmp/${MODUL_NAME} ] && rm -rf /tmp/${MODUL_NAME}
+    mkdir -p /tmp/${MODUL_NAME}
+    cd /tmp/${MODUL_NAME} && touch build.log error.log
+
+    if [ -z "${MODUL_NAME}" -o -z "${svn_number}" -o -z "${PROJECT_NAME}" ]
+    then
+        fn_print_err "Jenkins SVN version or modul name or project name does not exist." || return $?
+    fi
+
+    #通过网元模块名和svn版本号找到包名
+    pkg_name=`ls /data/ftp |grep -i ${MODUL_NAME} |grep ${svn_number} |tail -n 1`
+    if [ -z "${pkg_name}" ]
+    then
+        fn_print_err "SVN version or modul name is Error." || return $?
+    fi
+    local pkg_dir=`echo ${pkg_name} |awk -F'-' '{print $1}'`
+
+    #获取拆分变量
+    local images_name wangyuan_version
+    WANGYUAN_NAME=`echo ${pkg_name} |awk -F'_' '{print $1}' |tr [A-Z] [a-z]`
+    local server_name=`echo ${pkg_name} |awk -F'_' '{print $2}' |tr [A-Z] [a-z]`
+    if echo "${server_name}" |grep [0-9] >/dev/null 2>&1
+    then
+        images_name="${WANGYUAN_NAME}"
+        wangyuan_version=`echo ${pkg_name} |awk -F'_' '{print $2}'`
+    else
+        images_name="${server_name}"
+        wangyuan_version=`echo ${pkg_name} |awk -F'_' '{print $3}'`
+    fi
+
+    #拼接镜像的版本号,由网元版本号和svn版本号组成
+    IMAGE_VERSION="${wangyuan_version}"-"${svn_number}"
+
+    #提取Dockerfile文件
+    cp /data/ftp/${pkg_name} /tmp/${MODUL_NAME}
+    cd /tmp/${MODUL_NAME} && tar -zxvf ${pkg_name} --wildcards ${pkg_dir}/Dockerfile
+    cp -p ${pkg_dir}/Dockerfile ./ && rm -rf  ${pkg_dir}
+
+    #build镜像
+    cd /tmp/${MODUL_NAME}
+    tms_success "Start build ${MODUL_NAME} images."
+    
+    fn_build_images "${images_name}" >"${ERROR_LOG}" 2>&1
+    if [ $? -ne 0 ]
+    then
+        fn_print_err "build <${images_name}> failure." || return $?
+    fi
+
+    #清理临时目录
+	tms_success "Build ${MODUL_NAME} images Success."
+    cd /tmp && rm -rf "${MODUL_NAME}"    
+    
+    return 0
+
+}
+
+####################################################################################
+fn_main  $1 $2 $3 || exit $?
+####################################################################################
+

+ 189 - 0
deploy/deploy_powercloud_latest.sh

@@ -0,0 +1,189 @@
+#!/bin/bash
+# Usage:
+# deploy all(skip installed stack):     ./$1
+# deploy & upgrade:                     ./$1 --upgrade
+# deploy force(rm stack, then deploy)   ./$1 --force
+# deploy specify app:                   ./$1 --module="modle1,module2,module3"
+# deploy to specify env:                ./$1 --env="test"
+
+
+
+# deploy base dir
+WORKDIR="/tmp/powercloud_deploy"
+
+# default modules
+#APP="ues aaa cas authcenter dcmp"
+
+# get user selected modules
+SELECTED_APP=`echo $* | xargs -n 1 | grep "\-module" | awk -F"=" '{print $2}' | tr ',' ' '`
+
+# stack contain one or more submodule's name
+for i in $SELECTED_APP; do
+    DEPLOY_APP="$DEPLOY_APP ${i%%_*}"
+done
+
+# sort and uniq
+DEPLOY_APP=$(echo $DEPLOY_APP | xargs -n1 | sort | uniq | xargs)
+
+cat <<'EOF'
+
+     _            _                      _             _
+  __| | ___ _ __ | | ___  _   _      ___| |_ __ _ _ __| |_
+ / _` |/ _ \ '_ \| |/ _ \| | | |    / __| __/ _` | '__| __|
+| (_| |  __/ |_) | | (_) | |_| |    \__ \ || (_| | |  | |_
+ \__,_|\___| .__/|_|\___/ \__, |    |___/\__\__,_|_|   \__|
+           |_|            |___/
+
+EOF
+
+
+# if no select, use defult
+[ -n "$DEPLOY_APP" ] && APP=$DEPLOY_APP && \
+      echo "start to deploy app: $APP" && echo
+
+
+# git address
+GIT_TEMPLATE_URL="git@git.svicloud.com:svicloud/catalog-powercloud.git"
+#GIT_MODULE_VERSION_URL=http://git.sviyun.com/svicloud/catalog-powercloud/raw/master/version.json
+
+# service connect string(use dev env key & secret)
+RANCHER_URL=http://console.sviyun.com:8080/v1
+
+
+# update the git repo
+if [ -d ${WORKDIR}/powercloud-catalog/.git ]; then
+    cd ${WORKDIR}/powercloud-catalog
+    git --no-pager log  --graph \
+    --pretty=format:'%h - %d% %s (%cr [%an])' \
+    --abbrev-commit --date=relative  -20
+    echo;echo
+    git fetch --all
+    git reset --hard origin/master
+else
+    git clone $GIT_TEMPLATE_URL ${WORKDIR}/powercloud-catalog
+fi
+
+ENV=`echo $* | xargs -n 1 | grep "\-env" | awk -F"=" '{print $2}' | tr ',' ' '`
+echo "deploy to env=$ENV"
+if [ "$ENV" == "cs" ]; then
+    RANCHER_ACCESS_KEY=B437EF7772D5F4D145A0
+    RANCHER_SECRET_KEY=NNKVsUHqjQKemGRqcXCar521qjfh9dcurWT9CLj4
+elif [ "$ENV" == "test" ]; then
+    RANCHER_ACCESS_KEY=xxxxxxxxxxxx
+    RANCHER_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+elif [ "$ENV" == "powercloud" ]; then
+    RANCHER_ACCESS_KEY=DB9833C639BCA696277F
+    RANCHER_SECRET_KEY=dJBSgKxYUSXTm2n7dvijsjdndt8P37srrhZxwgqE
+elif [ "$ENV" == "powercloudtest" ]; then
+    RANCHER_ACCESS_KEY=xxxxxxxxxxxx
+    RANCHER_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+else
+    echo "Please specify the right env that has access key and secret key, exit!"
+    exit 1
+fi
+
+export RANCHER_URL  RANCHER_ACCESS_KEY  RANCHER_SECRET_KEY \
+
+
+# get the laste redis docker-compose & rancher-compose
+for module in $APP; do
+    echo -e "\nCurrent: $module"
+
+    # if has another process
+    retry=100
+    while true; do
+        ps_count=`ps -ef | grep "deploy_latest" | grep -q "$module" | wc -l`
+        retry_count=`expr $retry_count + 1`
+
+        # 100 times
+        if [ "$retry_count" -ge $retry ]; then
+            echo "timeout, coutinue."
+            break
+        fi
+
+        # has other process
+        if [ $ps_count -ge 2 ] ; then
+          echo "another process \"$module\" is running, waiting."
+          sleep 1
+        else
+          break
+        fi
+
+    done
+    # prepare the sub dir
+    mkdir -p $WORKDIR/$module
+    cd $WORKDIR/$module
+
+    # get the module version
+    # VARS=`curl $GIT_MODULE_VERSION_URL 2>/dev/null | jq .${module} \
+    # | sed "s/[ \t]*:[ \t]*/=/g" | tr -d ',"{} ' | xargs -n1 | sed 's/^/export /'`
+
+    # # export to shell
+    # if [[ "$module" != "redis" ]]; then
+        # # export the key
+        # if ! eval "$VARS" >/dev/null 2>&1; then
+            # echo "eval failed, please use: curl $GIT_MODULE_VERSION_URL to confirm!"
+            # exit 1
+        # else
+            # echo "VARS: $VARS"
+        # fi
+    # fi
+
+    cd ${WORKDIR}/powercloud-catalog/templates/$module/0
+    #curl -OL ${GIT_TEMPLATE_URL}/$module/0/rancher-compose.yml . 2>/dev/null
+    #curl -OL ${GIT_TEMPLATE_URL}/$module/0/docker-compose.yml . 2>/dev/null
+
+    dos2unix * &>/dev/null
+
+    # replace the VERSION string
+    #sed -i 's/@{.*VERSION}/latest/' rancher-compose.yml
+    #sed -i 's/@{.*VERSION}/latest/' docker-compose.yml
+
+    # has question
+    if grep -q "question" rancher-compose.yml; then
+        # has answer.txt
+        if [ -f "answer.txt" ]; then
+            ENV_ARGS="--env-file answer.txt"
+        # has not answer.txt
+        else
+            answer_exists=false
+            echo "you define questions in docker-compose.yml"
+            echo "but there is no answer.txt in the compose directory, exit!"
+            exit 5
+        fi
+     else
+        ENV_ARGS=""
+     fi
+
+    # compose up
+    if echo "$*" | grep -q "\-force"; then
+        echo "removing $module..."
+        sleep 1
+        rancher-compose -p ${module} $ENV_ARGS rm -f
+        sleep 1
+  rancher-compose -p ${module} $ENV_ARGS rm -f 2>/dev/null
+  sleep 5
+  echo "remove complete"
+    fi
+
+    # compose upgrade
+    echo
+    if echo "$*" | grep -q "\-upgrade"; then
+        echo "creating & upgrade $module..."
+        sleep 1
+        # TODO
+        if ! rancher-compose -p ${module} $ENV_ARGS upgrade $old_service $new_service; then
+            echo "rancher-compose -p ${module} upgrade failed, exit!"
+            exit 1
+        fi
+    else
+        echo "creating & up $module..."
+        sleep 1
+        if ! rancher-compose -p ${module} $ENV_ARGS up -d; then
+            echo "rancher-compose -p ${module} up -d failed, exit!"
+            exit 1
+        fi
+    fi
+
+
+done

+ 196 - 0
deploy/deploy_wisecloud_latest.sh

@@ -0,0 +1,196 @@
+#!/bin/bash
+# Usage: 
+# deploy all(skip installed stack):     ./$1
+# deploy & upgrade:                     ./$1 --upgrade
+# deploy force(rm stack, then deploy)   ./$1 --force
+# deploy specify app:                   ./$1 --module="modle1,module2,module3"
+# deploy to specify env:                ./$1 --env="test"
+
+
+
+# deploy base dir
+WORKDIR="/tmp/wisecloud_deploy"
+
+# default modules
+#APP="ues aaa cas authcenter dcmp"
+
+# get user selected modules
+SELECTED_APP=`echo $* | xargs -n 1 | grep "\-module" | awk -F"=" '{print $2}' | tr ',' ' '`
+
+# stack contain one or more submodule's name
+for i in $SELECTED_APP; do
+    DEPLOY_APP="$DEPLOY_APP ${i%%_*}"
+done
+
+# sort and uniq
+DEPLOY_APP=$(echo $DEPLOY_APP | xargs -n1 | sort | uniq | xargs)
+
+cat <<'EOF'
+
+     _            _                      _             _   
+  __| | ___ _ __ | | ___  _   _      ___| |_ __ _ _ __| |_ 
+ / _` |/ _ \ '_ \| |/ _ \| | | |    / __| __/ _` | '__| __|
+| (_| |  __/ |_) | | (_) | |_| |    \__ \ || (_| | |  | |_ 
+ \__,_|\___| .__/|_|\___/ \__, |    |___/\__\__,_|_|   \__|
+           |_|            |___/                            
+
+EOF
+
+
+# if no select, use defult
+[ -n "$DEPLOY_APP" ] && APP=$DEPLOY_APP && \
+      echo "start to deploy app: $APP" && echo
+
+
+# git address
+GIT_TEMPLATE_URL="git@git.sviyun.com:svicloud/catalog-wisecloud.git"
+#GIT_MODULE_VERSION_URL=http://git.sviyun.com/svicloud/catalog-wisecloud/raw/master/version.json
+
+# service connect string(use dev env key & secret)
+RANCHER_URL=http://console.sviyun.com:8080/v1
+
+
+# update the git repo
+if [ -d ${WORKDIR}/wisecloud-catalog/.git ]; then
+    cd ${WORKDIR}/wisecloud-catalog
+    git --no-pager log  --graph \
+    --pretty=format:'%h - %d% %s (%cr [%an])' \
+    --abbrev-commit --date=relative  -20
+    echo;echo
+    git fetch --all
+    git reset --hard origin/master
+else
+    git clone $GIT_TEMPLATE_URL ${WORKDIR}/wisecloud-catalog
+fi
+
+ENV=`echo $* | xargs -n 1 | grep "\-env" | awk -F"=" '{print $2}' | tr ',' ' '`
+echo "deploy to env=$ENV"
+if [ "$ENV" == "dev" ]; then
+    RANCHER_ACCESS_KEY=AADEA447C0DCD1B548BC
+    RANCHER_SECRET_KEY=Fm3Zm851Euw2rUSLAE9DQuZokcU4BD9DF5KXMMJh
+elif [ "$ENV" == "test" ]; then
+    RANCHER_ACCESS_KEY=FCCCE0B1257A2351A6A6
+    RANCHER_SECRET_KEY=cSSibMij1yBKJTnCBPPtvmm5eTXMBhLLEV2Wyn2A
+elif [ "$ENV" == "cs" ]; then
+    RANCHER_ACCESS_KEY=B437EF7772D5F4D145A0
+    RANCHER_SECRET_KEY=NNKVsUHqjQKemGRqcXCar521qjfh9dcurWT9CLj4
+elif [ "$ENV" == "pro" ]; then
+    RANCHER_ACCESS_KEY=xxxxxxxxxxxx
+    RANCHER_SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+else
+    echo "Please specify the right env that has access key and secret key, exit!"
+    exit 1
+fi
+
+redis_password=123456
+redis_port=7000
+postgres_user=postgres_user
+postgres_password=postgres_password
+pgdata="/var/lib/postgresql/data/pgdata"
+
+export RANCHER_URL  RANCHER_ACCESS_KEY  RANCHER_SECRET_KEY \
+        redis_password REDIS_PORT postgres_user postgres_password pgdata
+
+
+# get the laste redis docker-compose & rancher-compose
+for module in $APP; do
+    echo -e "\nCurrent: $module"
+
+    # if has another process
+    retry=100
+    while true; do
+        ps_count=`ps -ef | grep "deploy_latest" | grep -q "$module" | wc -l`
+        retry_count=`expr $retry_count + 1`
+        
+        # 100 times 
+        if [ "$retry_count" -ge $retry ]; then
+            echo "timeout, coutinue."
+            break
+        fi
+        
+        # has other process 
+        if [ $ps_count -ge 2 ] ; then
+          echo "another process \"$module\" is running, waiting."
+          sleep 1
+        else
+          break
+        fi
+        
+    done
+    # prepare the sub dir
+    mkdir -p $WORKDIR/$module
+    cd $WORKDIR/$module
+    
+    # get the module version
+    # VARS=`curl $GIT_MODULE_VERSION_URL 2>/dev/null | jq .${module} \
+    # | sed "s/[ \t]*:[ \t]*/=/g" | tr -d ',"{} ' | xargs -n1 | sed 's/^/export /'`
+    
+    # # export to shell
+    # if [[ "$module" != "redis" ]]; then
+        # # export the key
+        # if ! eval "$VARS" >/dev/null 2>&1; then
+            # echo "eval failed, please use: curl $GIT_MODULE_VERSION_URL to confirm!"
+            # exit 1
+        # else
+            # echo "VARS: $VARS"
+        # fi
+    # fi
+    
+    cd ${WORKDIR}/wisecloud-catalog/templates/$module/0
+    #curl -OL ${GIT_TEMPLATE_URL}/$module/0/rancher-compose.yml . 2>/dev/null
+    #curl -OL ${GIT_TEMPLATE_URL}/$module/0/docker-compose.yml . 2>/dev/null
+
+    dos2unix * &>/dev/null
+
+    # replace the VERSION string
+    #sed -i 's/@{.*VERSION}/latest/' rancher-compose.yml
+    #sed -i 's/@{.*VERSION}/latest/' docker-compose.yml
+    
+    # has question
+    if grep -q "question" rancher-compose.yml; then
+        # has answer.txt
+        if [ -f "answer.txt" ]; then
+            ENV_ARGS="--env-file answer.txt"
+        # has not answer.txt
+        else
+            answer_exists=false
+            echo "you define questions in docker-compose.yml"
+            echo "but there is no answer.txt in the compose directory, exit!"
+            exit 5
+        fi
+     else
+        ENV_ARGS=""
+     fi
+
+    # compose up
+    if echo "$*" | grep -q "\-force"; then
+        echo "removing $module..."
+        sleep 1
+        rancher-compose -p ${module} $ENV_ARGS rm -f
+        sleep 1
+	rancher-compose -p ${module} $ENV_ARGS rm -f 2>/dev/null
+	sleep 5
+	echo "remove complete"
+    fi
+
+    # compose upgrade
+    echo
+    if echo "$*" | grep -q "\-upgrade"; then
+        echo "creating & upgrade $module..."
+        sleep 1
+        # TODO
+        if ! rancher-compose -p ${module} $ENV_ARGS upgrade <old_service> <new_service>; then 
+            echo "rancher-compose -p ${module} upgrade failed, exit!"
+            exit 1
+        fi
+    else
+        echo "creating & up $module..."
+        sleep 1
+        if ! rancher-compose -p ${module} $ENV_ARGS up -d; then
+            echo "rancher-compose -p ${module} up -d failed, exit!"
+            exit 1
+        fi
+    fi
+    
+    
+done

+ 147 - 0
docker/start.sh

@@ -0,0 +1,147 @@
+#!/bin/bash
+# usage: check/replace/serivce_wait/service_start
+cd $(dirname $0)
+echo
+
+# version
+if [ -f ${APP_HOME}/${APP_NAME}/VERSION ]; then
+    echo -e "Checking env for ${APP_NAME}..\n`cat ${APP_HOME}/${APP_NAME}/VERSION`"
+else
+    echo "Checking env for ${APP_NAME}.."
+fi
+
+# check dir
+if [ -d ../conf ]; then
+    cd ../conf
+else
+    echo "please put conf/ and start.sh to the same directory."
+    exit 1
+fi
+
+# get conf files
+CONF_FILES=`find $(pwd) -type f | grep -v "\.svn" | grep -v "\.git"`
+
+# if no config file exists
+if [ -z "$CONF_FILES" ]; then
+    echo "No conf files found, pass."
+fi
+
+# has config file
+for f in $CONF_FILES; do
+
+    # metadata => "<location:LOCATION_OF_FILE> [MODE:600] [OWNER:USERNAME]"
+    # if there is " " " in value, use "\"  to escape
+    # use "${APP_HOME}/${APP_NAME}" to module home
+
+    # dos2unix
+    if which dos2unix &>/dev/null; then
+        dos2unix $f
+    else
+        sed -i 's/.$//' $f
+    fi
+
+    # get the location of metadata
+    METADATA_LOCATION=$(grep -iw metadata $f | awk -F'=>' '{print $2}' | \
+                      awk -F'location:' '{print $2}' | sed -n '1p' | \
+                      awk '{print $1}' | tr -d ',;"' | tr -d "'")
+
+    # replace the variable to true path
+    METADATA_LOCATION=`eval echo $METADATA_LOCATION`
+
+    # there is no location tag of metadata
+    if [ -z "$METADATA_LOCATION" ]; then
+        echo "\"location\" of metadata in \"$f\" not define!"
+        check_passed="$check_passed false"
+        continue
+    else
+        # if is a path
+        if `dirname $METADATA_LOCATION &>/dev/null`; then
+
+            # if does not exist, mkdir
+            if ! [ -d "$(dirname $METADATA_LOCATION)" ]; then
+                echo "mkdir -p $(dirname $METADATA_LOCATION)"
+                mkdir -p $(dirname $METADATA_LOCATION)
+            fi
+        else
+            echo "\"location\" of metadata in \"$f\" not PATH format!"
+            check_passed="$check_passed false"
+            continue
+        fi
+        dockerize_template="${dockerize_template} -template ${f}:${METADATA_LOCATION}"
+    fi
+
+    # has location but no {{ VAR }}
+    VAR_IN_BRACE=$(grep {{.*}} $f | sed -n 's/.*{{ *\(.*\) *}}.*/\1/p')
+    if [ -z "$VAR_IN_BRACE" ]; then
+        echo "skip \"${f}\" without replacing, pass."
+        continue
+
+    # has location and {{ VAR }}
+    else
+        # loop to check
+        for i in $VAR_IN_BRACE; do
+            VAR_TO_CHECK=${i##.Env.}
+            VAR_TO_CHECK=`echo $VAR_TO_CHECK`
+
+            # Check the value
+            if [ -z "${!VAR_TO_CHECK}" ]; then
+                echo "Can not get env: \"${VAR_TO_CHECK}\" in file: \"$f\" !"
+                check_passed="$check_passed false"
+            else
+                echo "|- ${VAR_TO_CHECK}=${!VAR_TO_CHECK}"
+            fi
+        done
+    fi
+done
+
+# if error, exit
+if echo $check_passed | grep -wq "false"; then
+    echo
+    echo "To inject variables to container, you can do it in:"
+    echo "  1. Dockerfile"
+    echo "  2. compose file (recommand)"
+    echo "  3. docker run with \"-e\" option"
+    echo "And you can receive value with \"{{ .Env.VARIABLE_NAME }}\" in config file."
+    echo
+    exit 1
+else
+    echo "Env check pass."
+    echo
+fi
+
+# get dependice
+for i in ${!APP_DEP*}; do
+    dockerize_wait="${dockerize_wait} -wait ${!i}"
+done
+
+
+# replace、Serivce wait、Service start
+echo -n "Pre-starting.."
+dockerize \
+    ${dockerize_template} \
+    ${dockerize_wait} -timeout 1200s \
+    -stdout    /var/log/${APP_NAME}.log \
+    -stderr    /var/log/${APP_NAME}.log \
+    echo "done"
+echo
+
+
+# start, important
+Service_Start() {
+    echo "Starting ${APP_NAME}.."
+
+    ####### START COMMAND HERE #########
+    set -e
+    start_${APP_NAME} && \
+    echo "success" && \
+    tail -f /var/log/${APP_NAME}.log
+
+    ####################################
+
+}
+
+# default: start the service
+Service_Start
+
+
+