blob: 65ea14e9cae3754d9a4007f8708fb9c5b0c73e0f [file] [log] [blame]
srikanth116e6e82014-08-19 07:22:37 -07001#!/bin/bash
2#
3# Copyright (c) 2013 Big Switch Networks, Inc.
4#
5# Licensed under the Eclipse Public License, Version 1.0 (the
6# "License"); you may not use this file except in compliance with the
7# License. You may obtain a copy of the License at
8#
9# http://www.eclipse.org/legal/epl-v10.html
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied. See the License for the specific language governing
15# permissions and limitations under the License.
16
17#
18# This script is invoked as part of VRRP track_script function
19# The goal is to do a health check of sdnplatform through a rest API
20# invocation, and if health is not good, then return with error code
21#
22if [ -e "/opt/sdnplatform/health-check-error-message" ]
23then
24 rm -f /opt/sdnplatform/health-check-error-message
25fi
26
27FAILOVER=$3
28
29if [ -e "/opt/sdnplatform/force-one-time-health-check-failure" ]
30then
31 logger "$0: force-one-time-health-check-failure file exists -- returning error exit code"
32 rm -f /opt/sdnplatform/force-one-time-health-check-failure
33 echo "User requested failover." > /opt/sdnplatform/health-check-error-message
34 exit 1
35fi
36
37if [ "$FAILOVER" ] ; then
38 exit 0
39fi
40
41if [ -e "/var/run/sdnplatform-healthcheck-disabled" ]; then
42 OLD=`cat /var/run/sdnplatform-healthcheck-disabled`
43 NEW=`date +%s`
44 if [ $NEW -gt $OLD ]; then
45 # if new timestamp is greater, remove the file and do health check
46 rm -f /var/run/sdnplatform-healthcheck-disabled
47 else
48 # skip the health check and exit
49 exit 0
50 fi
51fi
52
53COUNT=$1
54STEP=$2
55TIMER=0
56start="$(date +%s%N)"
57while [ $TIMER -le $COUNT ] ; do
58 curl -f -s "http://localhost:8080/wm/core/health/json"
59 ERROR=$?
60 if [ $ERROR -eq 0 ]; then
61 break
62 fi
63 sleep $STEP
64 TIMER=$((STEP+TIMER))
65done
66duration="$(($(date +%s%N)-start))"
67duration="$((duration/1000000))"
68logger "ha-health checker took $duration milliseconds"
69if [ $ERROR -ne 0 ]; then
70 logger "$0: sdnplatform health check failed with error code $ERROR"
71 echo "Controller health check failed." > /opt/sdnplatform/health-check-error-message
72 exit 1
73fi
74
75exit 0