Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make sure we monitor/unmonitor the slave properties

  • Loading branch information...
commit 2cf577c92316b54f499b2bc5b62e3feec438dcc3 1 parent 72627cd
@truthtrap truthtrap authored
Showing with 30 additions and 28 deletions.
  1. +30 −28 host.py
View
58 host.py
@@ -72,35 +72,37 @@ def set_master(self, master=None):
try:
os.system("/usr/bin/monit monitor redis")
if None == master:
- self.__log('slaveof()', 'info')
- self.redis.slaveof()
-
- self.__log('monit unmonitor initializing', 'info')
- os.system("/usr/bin/monit unmonitor initializing")
-
- self.__log('monit unmonitor slave', 'info')
- os.system("/usr/bin/monit unmonitor slave")
+ try:
+ self.__log('slaveof()', 'info')
+ self.redis.slaveof()
+ finally:
+ self.__log('monit unmonitor initializing', 'info')
+ os.system("/usr/bin/monit unmonitor initializing")
+
+ self.__log('monit unmonitor slave', 'info')
+ os.system("/usr/bin/monit unmonitor slave")
else:
- self.__log('slaveof({0})'.format(master), 'info')
- while True:
- try:
- self.redis.slaveof(master, 6379)
- self.__log('master now: ({0})'.format(master), 'info')
- break
- except Exception as e:
- self.__log(e, 'error')
- if str(e) == "Redis is loading data into memory":
- self.__log('retrying slaveof, in a sec', 'info')
- time.sleep(1)
- else:
- self.__log('different error', 'info')
- raise e
-
- self.__log('monit monitor initializing', 'info')
- os.system("/usr/bin/monit monitor initializing")
-
- self.__log('monit monitor slave', 'info')
- os.system("/usr/bin/monit monitor slave")
+ try:
+ self.__log('slaveof({0})'.format(master), 'info')
+ while True:
+ try:
+ self.redis.slaveof(master, 6379)
+ self.__log('master now: ({0})'.format(master), 'info')
+ break
+ except Exception as e:
+ self.__log(e, 'error')
+ if str(e) == "Redis is loading data into memory":
+ self.__log('retrying slaveof, in a sec', 'info')
+ time.sleep(1)
+ else:
+ self.__log('different error', 'info')
+ raise e
+ finally:
+ self.__log('monit monitor initializing', 'info')
+ os.system("/usr/bin/monit monitor initializing")
+
+ self.__log('monit monitor slave', 'info')
+ os.system("/usr/bin/monit monitor slave")
except Exception as e:
self.__log(e, 'error')
Please sign in to comment.
Something went wrong with that request. Please try again.