[Tree-wide] Make chart build process predictible
[oom.git] / kubernetes / sdnc / components / sdnc-prom / resources / bin / ensureSdncStandby.sh
1 #!/bin/bash
2
3 # Copyright © 2018 Amdocs
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
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 implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 debugLog(){
18   if [ "$enableDebugLogging" == true ]; then
19      if [ $# -eq 0 ]; then
20        echo "" >> $LOGFILE
21      else
22        echo $( date ) $@ >> $LOGFILE
23     fi
24   fi
25 }
26
27 LOGFILE="/app/geo.log"
28 enableDebugLogging=true
29
30 debugLog
31 debugLog "Executing ensureSdncStandby"
32
33 # query SDN-C cluster status
34 debugLog "Started executing sdnc.cluster"
35 clusterStatus=$( /app/bin/sdnc.cluster )
36 debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus"
37
38 if [ "active" = "$clusterStatus" ]; then
39   # assume transient error as other side transitions to ACTIVE
40   debugLog "Cluster status: $clusterStatus. exit 0"
41   exit 0
42
43 elif [ "standby" = "$clusterStatus" ]; then
44   # check that standby cluster is healthy
45   debugLog "Started executing sdnc.monitor. Cluster status is: $clusterStatus"
46   health=$( /app/bin/sdnc.monitor )
47   debugLog "Completed executing sdnc.monitor. Cluster is: $health"
48   if [ "failure" = "$health" ];then
49     # Backup site is unhealthy - can't accept traffic!
50     exit 1
51   fi
52   # Cluster is standing by
53   exit 0
54 fi
55
56 debugLog "Unknown cluster status: $clusterStatus"
57 # Unknown cluster status
58 exit 1