标签:url running coding api vat sts tco pipe bcb
1 #!/bin/bash 2 # ./ci_guard.sh 3 4 ERRORSTATUS=10 5 TESTSTATUS=0 6 USER="moonx" 7 IPs="192.168.1.102 192.168.1.102 " # add host ip like "xx.xx.xx.xx xx.xx.xx.xx", delimit by space 8 9 restart_gitlab_runner(){ 10 # restart gitlab-runner ssh ${USER}@${IP} 11 for IP in ${IPs} 12 do 13 echo "restart gitlab-runner on ${IP}: ssh ${USER}@${IP}" 14 #ssh ${USER}@${IP} "sudo service gitlab-runner restart; exit" 15 #ssh ${USER}@${IP} "pidof redis-server|sudo xargs kill -9; exit" 16 ssh ${USER}@${IP} "pidof redis-server|sudo xargs kill -9; exit" 17 sleep 3 18 done 19 } 20 21 test_(){ 22 for IP in ${IPs} 23 do 24 echo "on ${IP}: ssh ${USER}@${IP}" 25 ssh ${USER}@${IP} "date >> /usr/download/testcov/log; exit" 26 sleep 3 27 done 28 } 29 30 echo ‘begin guard the ci.‘ 31 #while true 32 #do 33 # get pipelines info 34 pipelinesinfo=`curl --header "PRIVATE-TOKEN: UsDsmqSpivXMmNoCHcci" 35 "https://gitlab.moonx.cn/api/v4/projects/2/pipelines" --insecure` # |python -m json.tool` 36 runnersinfo=`curl --header "PRIVATE-TOKEN: UsDsmqSpivXMmNoCHcci" 37 "https://gitlab.moonx.cn/api/v4/projects/2/runners" --insecure` 38 39 # resolve pipelines info 40 python checkcistatus.py $pipelinesinfo $runnersinfo 41 ci_status=$? 42 43 if [ $ERRORSTATUS == $ci_status ] 44 then 45 echo "49" 46 #restart_gitlab_runner 47 elif [ $TESTSTATUS == $ci_status ] 48 then 49 echo "55" 50 #test_ 51 fi 52 53 #sleep 5 54 #done 55 echo ‘exit guard the ci.‘
1 # coding=utf-8 2 # python checkcistatus.py $pipelinesinfo $runnersinfo 3 4 import sys 5 import re 6 7 ERRORSTATUS=10 8 9 pipeidstr=‘"id":‘ 10 pendingpipe=‘"status":"pending"‘ 11 runningpipe=‘"status":"running"‘ 12 13 template_str_runner=‘"name":"gitlab-runner"‘ 14 template_str_active_runner=‘"active":true‘ 15 16 if __name__ == "__main__": 17 if len(sys.argv) < 3: 18 print "usage: python checkcistatus.py $pipelinesinfo $runnersinfo" 19 sys.exit(1) 20 21 #for i in range(0,len(sys.argv)): 22 # print(i, sys.argv[i]) 23 pipe_num=len(re.findall(pipeidstr, sys.argv[1])) 24 runningpipe_num=len(re.findall(runningpipe, sys.argv[1])) 25 pendingpipe_num=len(re.findall(pendingpipe, sys.argv[1])) 26 print "pipe_num:%d,running:%d,pending:%d" % (pipe_num,runningpipe_num,pendingpipe_num) 27 28 runner_num=len(re.findall(template_str_runner, sys.argv[2])) 29 active_runner_num=len(re.findall(template_str_active_runner, sys.argv[2])) 30 print "runner:%d,active_runner:%d" % (runner_num,active_runner_num) 31 32 if 0==runningpipe_num and 0!=pendingpipe_num: 33 print "[error]no running pipeline, pending pipeline exists." 34 print "[error]need to restart gitlab-runner." 35 sys.exit(ERRORSTATUS) 36 37 if 0!=pendingpipe_num and runningpipeline_num < active_runner_num: 38 print "[error]running pipeline less than active runner, pending pipeline exists." 39 print "[error]need to restart gitlab-runner." 40 sys.exit(ERRORSTATUS) 41 42 print "[info]not need to restart gitlab-runner." 43 sys.exit(0)
标签:url running coding api vat sts tco pipe bcb
原文地址:https://www.cnblogs.com/cjyp/p/10387265.html