4 # Copyright © 2018 Amdocs
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 if [ "$enableDebugLogging" = true ]; then
24 echo $( date ) $@ >> $LOGFILE
30 lockFile=/tmp/sdnc.failover.lock
31 # make sure that no failover is currently running
32 if [ -e ${lockFile} ] && kill -0 $(cat ${lockFile}) 2> /dev/null; then
33 debugLog "Currently running sdnc and dns failover"
36 trap "rm -f ${lockFile}" INT TERM RETURN
37 echo $BASHPID > ${lockFile}
40 debugLog "Started executing sdnc.failover for $SITE_NAME"
41 takeoverResult=$( /app/bin/sdnc.failover )
42 debugLog "Completed executing sdnc.failover. takeoverResult is: $takeoverResult"
43 if [ "success" = "$takeoverResult" ]; then
44 # update CoreDNS upon successful execution of sdnc.failover script
45 debugLog "Executing sdnc.dnsswitch"
46 /app/bin/sdnc.dnsswitch
48 debugLog "Completed executing sdnc.dnsswitch for $SITE_NAME. rc=$rc"
50 debugLog "Cluster takeover current status: $takeoverResult on $SITE_NAME."
55 takeoverResult="failure"
59 \"type\": \"failover\",\
60 \"status\": \"$takeoverResult\",\
61 \"site\": \"$SITE_NAME\",\
62 \"deployment\": \"{{.Values.config.deployment}}\",\
63 \"timestamp\": \"$(date '+%F %T')\"\
66 # notifications are best-effort - ignore any failures
67 curl -H "Content-Type: application/json" -X POST --data "$data" http://$message_router/events/$topic >/dev/null 2>&1
71 LOGFILE="/app/geo.log"
72 enableDebugLogging=true
73 message_router=message-router:3904
74 topic={{.Values.config.messageRouterTopic}}
76 if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then
81 debugLog "Executing ensureSdncActive"
83 # query SDN-C cluster status
84 debugLog "Started executing sdnc.cluster"
85 clusterStatus=$( /app/bin/sdnc.cluster )
86 debugLog "Completed executing sdnc.cluster. Cluster status is: $clusterStatus"
88 if [ "active" = "$clusterStatus" ]; then
90 debugLog "Started excuting sdnc.monitor"
91 health=$( /app/bin/sdnc.monitor )
92 debugLog "Completed executing sdnc.monitor. Cluster is: $health"
94 if [ "healthy" = "$health" ]; then
95 # Cluster is ACTIVE and HEALTHY
100 elif [ "standby" = "$clusterStatus" ]; then
101 # Run failover in background process and allow PROM to continue
106 # Unknown cluster status