diff options
author | Philip Colmer <philip.colmer@linaro.org> | 2014-01-21 10:35:53 +0000 |
---|---|---|
committer | Philip Colmer <philip.colmer@linaro.org> | 2014-01-21 10:35:53 +0000 |
commit | e3e65f1e038c1dcd975d4edc2000cf3d84267df6 (patch) | |
tree | f231d54039ec74b9c9adabec085acdeddb02ead9 | |
parent | c009571d19cdf145bedcdf19c2217789f57d2718 (diff) |
Changed state logic so that it is now possible to switch from Active
to Passive.
-rw-r--r-- | healthcheck.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/healthcheck.py b/healthcheck.py index 0359e4b..4120dec 100644 --- a/healthcheck.py +++ b/healthcheck.py @@ -55,19 +55,25 @@ class HealthCheck(object): # The following logic ONLY works if: # a) there are two nodes # b) the IP addresses returned by Route 53 map onto those nodes + + # See if the external health checks think we're healthy? + healthy = os.path.isfile(self.script_directory + "/healthy") + if (service_ip != self.last_address): # Active node has changed if (self.last_state == States.Passive): # We've become the new active node - switch to starting up new_state = States.StartingUp if (self.last_state == States.Active): - # We were the active node - we must have failed - new_state = States.Failed + # We were the active node - see if we are still healthy, + # in which case we switch to passive, or if we have failed. + if (healthy): + new_state = States.Passive + else: + new_state = States.Failed else: if (service_ip == self.system_ip): # We're the active node. - # See if the external health checks think we're healthy? - healthy = os.path.isfile(self.script_directory + "/healthy") if (self.last_state == States.Maintenance): new_state = States.Passive if (self.last_state == States.Passive): @@ -150,7 +156,7 @@ class HealthCheck(object): if (new_state == States.Active or new_state == States.Failed or new_state == States.Maintenance or new_state == States.Frozen): valid_state = True elif (self.last_state == States.Active): - if (new_state == States.Failed or new_state == States.Maintenance or new_state == States.Frozen): + if (new_state == States.Failed or new_state == States.Maintenance or new_state == States.Frozen or new_state == States.Passive): valid_state = True elif (self.last_state == States.Failed): if (new_state == States.Maintenance or new_state == States.Frozen): |