Selaa lähdekoodia

update by krrish

krrish 6 vuotta sitten
vanhempi
commit
0165e3a8b8
3 muutettua tiedostoa jossa 52 lisäystä ja 15 poistoa
  1. 5 0
      Dockerfile.tpl
  2. 35 14
      deploy/deploy_latest.sh
  3. 12 1
      docker/start.sh

+ 5 - 0
Dockerfile.tpl

@@ -19,6 +19,11 @@ ENV JETTY_RUN ${JETTY_HOME}/bin
 ENV APP_DEP1 "tcp://postgres.postgres:5432"
 ENV APP_DEP2 "http://web.authcenter:80"
 
+######## 定义业务日志
+#   1、多个日志文件,可以继续加 APP_LOG3、APP_LOG4 ... APP_LOG<n>
+ENV APP_LOG1 "${APP_HOME}/${APP_NAME}/xxx.log"
+ENV APP_LOG2 "/var/log/THIS_IS_MY_LOG_LOCATION"
+
 ######## 以下内容无需编辑修改
 ADD *.tar.gz /tmp
 RUN cd /tmp/*_release && \

+ 35 - 14
deploy/deploy_latest.sh

@@ -1,9 +1,9 @@
 #!/bin/bash
 # Usage:
 # deploy with upgrade:                                  --upgrade, DO NOT USE
-# deploy force(rm stack, then deploy)                   --force (±ØÌî)
-# deploy specify app:                                   --module="ems_server" (±ØÌî)
-# deploy to specify env:                                --env="powercloud" (±ØÌî)
+# deploy force(rm stack, then deploy)                   --force (å¿…å¡«)
+# deploy specify app:                                   --module="ems_server" (å¿…å¡«)
+# deploy to specify env:                                --env="powercloud" (å¿…å¡«)
 # deploy with specify git branch, default master        --git-branch="dev" 
 # deploy with specify version, default 0                --compose_version=1
 
@@ -60,7 +60,7 @@ fi
 # fetch remote tags 
 git fetch --all
 
-GIT_BRANCH=`echo $* | xargs -n 1 | grep "\-git\-branch" | awk -F"=" '{print $2}' | tr ',' ' '`
+GIT_BRANCH=`echo $* | xargs -n 1 | grep "\-git\-branch" | awk -F"=" '{print $2}' | tr ',' ' ' | xargs`
 GIT_BRANCH=${GIT_BRANCH:-master}
 
 # has branch
@@ -68,9 +68,10 @@ if git branch -a | grep -wq "${GIT_BRANCH}"; then
 
     # if current branch not the wanted, checkout it
     current_branch=`git branch | grep "\*" | awk '{print $2}'`
+    
     if [ "${GIT_BRANCH}" != "${current_branch}" ]; then
         # checkout 
-        git checkout -b ${GIT_BRANCH} &>/dev/null
+        git checkout -b ${GIT_BRANCH}
     fi
     
     # reset hard the branch
@@ -79,6 +80,7 @@ if git branch -a | grep -wq "${GIT_BRANCH}"; then
 # no branch
 else
     echo "#####################################"
+    echo "You define the --git-branch=$GIT_BRANCH"
     echo "Please specify the right \"--git-branch\", exit!"
     echo "#####################################"
     exit 1
@@ -87,7 +89,13 @@ fi
 
 ENV=`echo $* | xargs -n 1 | grep "\-env" | awk -F"=" '{print $2}' | tr ',' ' '`
 echo "deploy to env=$ENV"
-if [ "$ENV" == "cs" ]; then
+if [ "$ENV" == "powercloudtest" ]; then
+    RANCHER_ACCESS_KEY=0CA5094E8E4562442D99
+    RANCHER_SECRET_KEY=7TH5j64DSUPFbf6b9cFr4mp7Brq5iUrPBSx6sJxM
+elif [ "$ENV" == "test" ]; then
+    RANCHER_ACCESS_KEY=C98222E5206624BFB807
+    RANCHER_SECRET_KEY=LBg2tF96miU8rBPgN2kR9uXV2qbrKKuQTrTEy5Wq
+elif [ "$ENV" == "cs" ]; then
     RANCHER_ACCESS_KEY=344E9FA150DD81B6F254
     RANCHER_SECRET_KEY=9tBspbMqp3ny8ZzXbBBTpYNke5fhgLPWfXyvqqTi
 
@@ -128,7 +136,7 @@ for module in $APP; do
     # if has another process
     retry=100
     while true; do
-        ps_count=`ps -ef | grep "deploy_latest" | grep -q "$module" | wc -l`
+        ps_count=`ps -ef | grep "deploy_latest" | grep "$module" | wc -l`
         retry_count=`expr $retry_count + 1`
 
         # 100 times
@@ -140,13 +148,15 @@ for module in $APP; do
         # has other process
         if [ $ps_count -ge 2 ] ; then
           echo "another process \"$module\" is running, waiting."
-          sleep 1
+          sleep 2
+          
         else
           break
         fi
 
     done
     # prepare the sub dir
+    echo "work directory: $WORKDIR/$module"
     mkdir -p $WORKDIR/$module
     cd $WORKDIR/$module
 
@@ -172,6 +182,7 @@ for module in $APP; do
     else
         compose_version_number=$COMPOSE_VERSION
     fi
+    
     if ! cd ${WORKDIR}/wisecloud-catalog/templates/$module/${compose_version_number}; then
         echo "  Maybe you have input the wrong compose_version"
         exit 1
@@ -205,13 +216,16 @@ for module in $APP; do
      fi
 
     # rancher-compose pull image
+    echo "pulling the latest image..."
     rancher-compose -p ${module} $ENV_ARGS pull
-
+    sleep 5
+    echo "ok, finish pulling the latest image..."
+    
     # compose up
     if echo "$*" | grep -q "\-force"; then
-        echo "removing $module..."
+        echo; echo "removing $module..."
         rancher-compose -p ${module} $ENV_ARGS rm -f
-        sleep 1
+        sleep 2
         # try again
         rancher-compose -p ${module} $ENV_ARGS rm -f 2>/dev/null
         sleep 3
@@ -244,7 +258,14 @@ for module in $APP; do
         fi
     fi
 
-
+   
 done
-
-
+cat <<'EOF'
+     _            _                   _                  
+  __| | ___ _ __ | | ___  _   _    __| | ___  _ __   ___ 
+ / _` |/ _ \ '_ \| |/ _ \| | | |  / _` |/ _ \| '_ \ / _ \
+| (_| |  __/ |_) | | (_) | |_| | | (_| | (_) | | | |  __/
+ \__,_|\___| .__/|_|\___/ \__, |  \__,_|\___/|_| |_|\___|
+           |_|            |___/                          
+
+EOF

+ 12 - 1
docker/start.sh

@@ -1,5 +1,6 @@
 #!/bin/bash
 # usage: check/replace/serivce_wait/service_start
+
 cd $(dirname $0)
 echo
 
@@ -125,6 +126,16 @@ dockerize \
     echo "done"
 echo
 
+# get logs
+for log in ${!APP_LOG*}; do
+
+    # pre-create log file
+    mkdir -p `dirname ${!log}`
+    touch ${!log}
+    
+    LOG_LIST="${LOG_LIST} ${!log}"
+done
+
 
 # start, important
 Service_Start() {
@@ -134,7 +145,7 @@ Service_Start() {
     set -e
     bash -x `which start_${APP_NAME}` && \
     echo "success" && \
-    tail -f /var/log/${APP_NAME}.log
+    tail -f /var/log/${APP_NAME}.log $LOG_LIST
 
     ####################################