Kaynağa Gözat

ci: 调整启动脚本,发布运行

许家凯 4 yıl önce
ebeveyn
işleme
876e385960
1 değiştirilmiş dosya ile 66 ekleme ve 69 silme
  1. 66 69
      start.sh

+ 66 - 69
start.sh

@@ -4,37 +4,66 @@ export JAVA_HOME=/root/jdk1.8.0_181
 export PATH=$JAVA_HOME/bin:$PATH
 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
 
-
 bashPath=/root/maxcompute_job/flow
+debug=0
+
+if [ $# -eq 0 ]; then
+  echo "---------------------------------------------------------------------------"
+  # OS Type
+  echo "                    OS Type: $(uname -o)"
+  # OS Release Version and Name
+  echo "OS Release Version and Name: $(cat /etc/issue | head -n 1)"
+  #Architecture
+  echo "               Architecture: $(uname -m)"
+  #Kernel Release
+  echo "             Kernel Release: $(uname -r)"
+  #hostname
+  echo "                   hostname: $HOSTNAME"
+  #Internal IP
+  echo "                Internal IP: $(hostname -I)"
+  #External IP
+  echo "                External IP: $(curl --connect-timeout 10 -m 20 -s ipecho.net/plain)"
+  #DNS
+  dnsservers=""
+  for i in $(cat /etc/resolv.conf | grep '^nameserver' | awk '{print $NF}'); do
+    dnsservers="$dnsservers$i "
+  done
+  echo "                        DNS: $dnsservers"
+  #if connected to Internet or not
+  echo "            internet status: $(ping -c 2 www.baidu.com &>/dev/null && echo 'connected' || echo 'disconnected')"
+  echo "---------------------------------------------------------------------------"
+fi
 
-if [ $# -eq 0 ];then
-        echo "---------------------------------------------------------------------------"
-        # OS Type
-        echo "                    OS Type: $(uname -o)"
-        # OS Release Version and Name
-        echo "OS Release Version and Name: $(cat /etc/issue | head -n 1)"
-        #Architecture
-        echo "               Architecture: $(uname -m)"
-        #Kernel Release
-        echo "             Kernel Release: $(uname -r)"
-        #hostname
-        echo "                   hostname: $HOSTNAME"
-        #Internal IP
-        echo "                Internal IP: $(hostname -I)"
-        #External IP
-        echo "                External IP: $(curl --connect-timeout 10 -m 20 -s ipecho.net/plain)"
-        #DNS
-        dnsservers=""
-        for i in $(cat /etc/resolv.conf | grep '^nameserver' | awk '{print $NF}')
-        do
-                dnsservers="$dnsservers$i "
-        done
-        echo "                        DNS: $dnsservers"
-        #if connected to Internet or not
-        echo "            internet status: $( ping -c 2 www.baidu.com &> /dev/null && echo 'connected' || echo 'disconnected')"
-        echo "---------------------------------------------------------------------------"
+if [ $# -eq 1 ]; then
+  echo "启动debug模式"
+  debug=1
 fi
 
+start_job() {
+  echo "start job:$1"
+  if [ $# -lt 1 ]; then
+    echo ""
+    # shellcheck disable=SC2242
+    exit -1
+  fi
+
+  if [ $debug -eq 1 ]; then
+    echo "debug model。。。"
+    java -jar $bashPath/DataWorks-flow-touch.jar -f $bashPath/jobs/$1 -d
+    return
+  else
+    ehco ""
+    java -jar $bashPath/DataWorks-flow-touch.jar -f $bashPath/jobs/$1
+  fi
+
+  if [ $? -eq 0 ]; then
+    echo "$1 succeed"
+  else
+    echo "$1 failed"
+    exit $?
+  fi
+}
+
 # shellcheck disable=SC2164
 cd $bashPath/repo
 
@@ -45,57 +74,25 @@ cd ..
 java -jar $bashPath/DataWorks-flow-touch.jar -w
 
 if [ $? -eq 0 ]; then
-     echo "上游数据已同步完成!"
+  echo "上游数据已同步完成!"
 else
-     echo "上游数据长时间未同步完成,程序中止!"
-     exit $?
+  echo "上游数据长时间未同步完成,程序中止!"
+  exit $?
 fi
 
 java -jar $bashPath/DataWorks-flow-touch.jar -q
 
 if [ $? -eq 0 ]; then
-     echo "company is not empty!"
-else
-     echo "company is empty!"
-     exit $?
-fi
-
-java -jar $bashPath/DataWorks-flow-touch.jar -f $bashPath/jobs/task-step01.yaml
-
-if [ $? -eq 0 ]; then
-     echo "step01 succeed"
+  echo "company is not empty!"
 else
-     echo "step01 failed"
-     exit $?
+  echo "company is empty!"
+  exit $?
 fi
 
-java -jar $bashPath/DataWorks-flow-touch.jar -f $bashPath/jobs/task-step02.yaml
-
-if [ $? -eq 0 ]; then
-     echo "step02 succeed"
-else
-     echo "step02 failed"
-     exit $?
-fi
+job_files=(task-step01.yaml task-step02.yaml task-step03.yaml task-step04.yaml)
 
-java -jar $bashPath/DataWorks-flow-touch.jar -f $bashPath/jobs/task-step03.yaml
-
-if [ $? -eq 0 ]; then
-     echo "step03 succeed"
-else
-     echo "step03 failed"
-     exit $?
-fi
-
-java -jar $bashPath/DataWorks-flow-touch.jar -f $bashPath/jobs/task-step04.yaml
-
-if [ $? -eq 0 ]; then
-     echo "step04 succeed"
-else
-     echo "step04 failed"
-     exit $?
-fi
+for e in ${job_files[@]}; do
+  start_job $e
+done
 
 echo "end"
-
-