Permalink
Browse files

slowly getting the launch sequence under control, monit was also star…

…ting before redis
  • Loading branch information...
truthtrap committed Jan 23, 2012
1 parent c1e4a68 commit 43bd051806c076ab55b7cae68807f95a64f45246
Showing with 28 additions and 36 deletions.
  1. +10 −10 host.py
  2. +4 −8 join.py
  3. +4 −5 leave.py
  4. +5 −4 monitor.py
  5. +5 −9 remaster.py
View
20 host.py
@@ -48,40 +48,40 @@ def __init__(self, cluster, events=None):
self.redis = redis.StrictRedis(host="localhost", port=6379)
self.events = events
- def __log(message, logging='warning'):
+ def __log(self, message, logging='warning'):
try:
- self.events.log(self.host.get_node(), 'Monitor', message, logging)
+ self.events.log(self.node, 'Host', message, logging)
except:
print "probably no 'events' object supplied"
def get_node(self):
- __log('get_node', 'info')
+ self.__log('get_node', 'info')
return self.node
def get_endpoint(self):
- __log('get_endpoint', 'info')
+ self.__log('get_endpoint', 'info')
return self.endpoint
def get_master(self):
- __log('get_master', 'info')
+ self.__log('get_master', 'info')
return self.master
def set_master(self, master=None):
- __log('set_master: {0}'.format(master), 'info')
+ self.__log('set_master: {0}'.format(master), 'info')
self.master = master
try:
- __log('monit monitor all', 'info')
+ self.__log('monit monitor all', 'info')
os.system("/usr/sbin/monit monitor all")
if None == master:
- __log('slaveof()', 'info')
+ self.__log('slaveof()', 'info')
self.redis.slaveof()
os.system("/usr/sbin/monit unmonitor slave")
else:
- __log('slaveof({0})'.format(master), 'info')
+ self.__log('slaveof({0})'.format(master), 'info')
self.redis.slaveof(master, 6379)
os.system("/usr/sbin/monit monitor slave")
except Exception as e:
- __log(e, 'error')
+ self.__log(e, 'error')
if __name__ == '__main__':
# easy testing, use like this (requires environment variables)
View
12 join.py
@@ -46,19 +46,15 @@
ec2 = EC2(key, access)
events = Events(key, access, cluster.name())
-node = Host(cluster, events).get_node()
+host = Host(cluster.name(), events)
+node = host.get_node()
+endpoint = host.get_endpoint()
component = os.path.basename(sys.argv[0])
def log(message, logging='info'):
events.log(node, component, message, logging)
if __name__ == '__main__':
log('joining the cluster', 'info')
- # and get the instance up and running
- log('configuring the host', 'info')
- host = Host(cluster.domain.name, events)
-
- node = host.get_node()
- endpoint = host.get_endpoint()
log('adding the node to the cluster', 'info')
# now we are ready to be (added to) the cluster
@@ -73,7 +69,7 @@ def log(message, logging='info'):
# if we don't have a master, we ARE the master
if master == None:
log('setting the main Route53 record for the cluster', 'info')
- r53_zone.update_record(cluster.domain.name, endpoint)
+ r53_zone.update_record(cluster.name(), endpoint)
# and make sure we 'run' correctly (no-slave, well-monitored)
log('set the host to run as master', 'info')
View
@@ -46,7 +46,9 @@
ec2 = EC2(key, access)
events = Events(key, access, cluster.name())
-node = Host(cluster, events).get_node()
+host = Host(cluster.name(), events)
+node = host.get_node()
+endpoint = host.get_endpoint()
component = os.path.basename(sys.argv[0])
def log(message, logging='info'):
events.log(node, component, message, logging)
@@ -56,13 +58,10 @@ def log(message, logging='info'):
try:
# get the host, us
log('get the host', 'info')
- host = Host(cluster.domain.name, events)
# make sure we are not connected to anything anymore
log('disconnect from other nodes', 'info')
host.set_master()
- node = host.get_node()
- endpoint = host.get_endpoint()
except Exception as e:
log(e, 'error')
@@ -87,6 +86,6 @@ def log(message, logging='info'):
size = cluster.size()
if size <= 0:
log('delete the master Route53 record', 'info')
- r53_zone.delete_record(cluster.domain.name)
+ r53_zone.delete_record(cluster.name())
except Exception as e:
log(e, 'error')
View
@@ -58,11 +58,12 @@ def __init__(self, key, access, cluster):
self.events = Events(key, access, cluster)
- # get the host
- self.host = Host(cluster, self.events)
+ # get the host, but without the logging
+ self.host = Host(cluster)
+ self.node = self.host.get_node()
def __log(self, message, logging='warning'):
- self.events.log(self.host.get_node(), 'Monitor', message, logging)
+ self.events.log(self.node, 'Monitor', message, logging)
def collect(self):
self.__log('collecting metrics data from Redis INFO', 'info')
@@ -73,7 +74,7 @@ def collect(self):
names = []
values = []
units = []
- dimensions = { 'node' : self.host.get_node(),
+ dimensions = { 'node' : self.node,
'cluster' : self.cluster }
if items['aof_enabled']:
View
@@ -44,20 +44,16 @@
ec2 = EC2(key, access)
events = Events(key, access, cluster.name())
-node = Host(cluster, events).get_node()
+host = Host(cluster.name(), events)
+node = host.get_node()
+endpoint = host.get_endpoint()
component = os.path.basename(sys.argv[0])
def log(message, logging='info'):
events.log(node, component, message, logging)
r = redis.StrictRedis(host='localhost', port=6379)
if __name__ == '__main__':
- # get the host (uses domain name, gets the rest from the instance itself)
- host = Host(cluster.domain.name, events)
-
- node = host.get_node()
- endpoint = host.get_endpoint()
-
# make sure we get the redis master, perhaps our master is already gone
# from the cluster
try:
@@ -94,8 +90,8 @@ def log(message, logging='info'):
log("{0} = cluster.get_master({1})".format(grandmaster, node), 'info')
if grandmaster == None:
- r53_zone.update_record(cluster.domain.name, endpoint)
- log("r53_zone.update_record({0}, {1})".format(cluster.domain.name, endpoint), 'info')
+ r53_zone.update_record(cluster.name(), endpoint)
+ log("r53_zone.update_record({0}, {1})".format(cluster.name(), endpoint), 'info')
host.set_master()
log("host.set_master()", 'info')
else:

0 comments on commit 43bd051

Please sign in to comment.