Skip to content

Commit

Permalink
Restart harbor job when detecting harbor service failure
Browse files Browse the repository at this point in the history
Because removing the harbor pid file only leads to harbor job start
rather than job restart, so the abnormal harbor containers can not
be destroyed and recreated.
  • Loading branch information
jessehu committed Dec 7, 2017
1 parent 469fbb2 commit bd9318e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions jobs/harbor/templates/bin/status_check.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Timestamp=`date '+%Y-%m-%d %H:%M:%S'`

#Exit function with pid file deletion
myExit() {
echo "$Timestamp Harbor status check: [FAILED]"
rm -f $PIDFILE
exit $1
echo "$Timestamp Harbor status check: [FAILED]"
echo "$Timestamp Now restart harbor job"
rm -f /etc/cron.d/harbor
/var/vcap/bosh/bin/monit restart harbor
exit $1
}

#Check if containers existing
Expand All @@ -40,19 +42,19 @@ protocol=<%= p("ui_url_protocol") %>

curl_command="curl -s"
if [ "$protocol" = "https" ]; then
curl_command="$curl_command --cacert $HARBOR_JOB_DIR/config/ca.crt"
curl_command="$curl_command --cacert $HARBOR_JOB_DIR/config/ca.crt"
fi

set +e

echo "${curl_command} ${protocol}://${harbor_url}/api/systeminfo"
url=`${curl_command} ${protocol}://${harbor_url}/api/systeminfo | python -c "import sys, json; print json.load(sys.stdin)['registry_url']"`
if [ $? != 0 ] ; then
myExit 3
myExit 3
fi

if [ -z "$url" ]; then
myExit 4
myExit 4
fi

#Check Docker Registry connectivity
Expand Down

0 comments on commit bd9318e

Please sign in to comment.