diff options
| -rwxr-xr-x | hooks/hooks.py | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/hooks/hooks.py b/hooks/hooks.py index eafce5a..a5dc09a 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -1166,12 +1166,6 @@ def replica_set_relation_joined(): juju_log("replica_set_relation_joined-finish") -def in_replica_set(): - c = Connection('localhost') - r = run_admin_command(c, 'isMaster') - return 'setName' in r - - def am_i_primary(): c = Connection('localhost') for i in xrange(10): @@ -1266,11 +1260,6 @@ def replica_set_relation_departed(): def replica_set_relation_broken(): juju_log('replica_set_relation_broken-start') - if not in_replica_set(): - juju_log('not in replica set', level=DEBUG) - juju_log('replica_set_relation_broken-finish') - return - if am_i_primary(): juju_log('I was primary - removing myself via new primary.', 'DEBUG') mongo_client('localhost', 'rs.stepDown()') @@ -1278,12 +1267,16 @@ def replica_set_relation_broken(): c = Connection('localhost') r = c.admin.command('isMaster') - master_node = r['primary'] - unit = "%s:%s" % (unit_get('private-address'), - config('port')) - - juju_log('Removing myself via %s' % (master_node), 'DEBUG') - leave_replset(master_node, unit) + + try: + master_node = r['primary'] + except KeyError: + pass + + if 'master_node' in locals(): # unit is part of replicaset, remove it! + unit = "%s:%s" % (unit_get('private-address'), config('port')) + juju_log('Removing myself via %s' % (master_node), 'DEBUG') + leave_replset(master_node, unit) juju_log('replica_set_relation_broken-finish') |
