Merge "[COMMON] Add custom certs into AAF truststore"
[oom.git] / kubernetes / sdnc / components / sdnc-prom / resources / bin / ensureSdncStandby.sh
1 #!/bin/bash
2 {{/*
3
4 # Copyright © 2018 Amdocs
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 */}}
18
19 debugLog(){
20   if [ "$enableDebugLogging" = true ]; then
21      if [ $# -eq 0 ]; then
22        echo "" >> $LOGFILE
23      else
24        echo $( date ) $@ >> $LOGFILE
25     fi
26   fi
27 }
28
29 LOGFILE="/app/geo.log"
30 enableDebugLogging=true
31
32 debugLog
33 debugLog "Executing ensureSdncStandby"
34
35 # query SDN-C cluster status
36 debugLog "Started executing sdnc.cluster"
37 clusterStatus=$( /app/bin/sdnc.cluster )
38 debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus"
39
40 if [ "active" = "$clusterStatus" ]; then
41   # assume transient error as other side transitions to ACTIVE
42   debugLog "Cluster status: $clusterStatus. exit 0"
43   exit 0
44
45 elif [ "standby" = "$clusterStatus" ]; then
46   # check that standby cluster is healthy
47   debugLog "Started executing sdnc.monitor. Cluster status is: $clusterStatus"
48   health=$( /app/bin/sdnc.monitor )
49   debugLog "Completed executing sdnc.monitor. Cluster is: $health"
50   if [ "failure" = "$health" ];then
51     # Backup site is unhealthy - can't accept traffic!
52     exit 1
53   fi
54   # Cluster is standing by
55   exit 0
56 fi
57
58 debugLog "Unknown cluster status: $clusterStatus"
59 # Unknown cluster status
60 exit 1