Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

and ... another try

  • Loading branch information...
commit 2411d25089f58cf3a792c849830f4c80763a6ea1 1 parent f6e075a
@truthtrap truthtrap authored
Showing with 103 additions and 6 deletions.
  1. +4 −0 etc/monit/redis.monitrc
  2. +6 −6 host.py
  3. +66 −0 reslave.py
  4. +27 −0 reslave.sh
View
4 etc/monit/redis.monitrc
@@ -20,3 +20,7 @@
send "PING\r\nINFO\r\n" expect "master_link_status:up"
3 cycles
then exec "/root/ReDiS/remaster.sh"
+
+ check file initilizing with path /var/run/redis/slave
+ if does not exist then exec "/root/ReDiS/reslave.sh"
+ else if succeeded then unmonitor
View
12 host.py
@@ -75,15 +75,12 @@ def set_master(self, master=None):
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")
-
- self.__log('removing /var/run/redis/slave', 'info')
- os.system("/bin/rm /var/run/redis/slave")
else:
- self.__log('creating /var/run/redis/slave', 'info')
- os.system("/usr/bin/touch /var/run/redis/slave")
-
self.__log('slaveof({0})'.format(master), 'info')
while True:
try:
@@ -99,6 +96,9 @@ def set_master(self, master=None):
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")
except Exception as e:
View
66 reslave.py
@@ -0,0 +1,66 @@
+# Copyright (C) 2011, 2012 9apps B.V.
+#
+# This file is part of Redis for AWS.
+#
+# Redis for AWS is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Redis for AWS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Redis for AWS. If not, see <http://www.gnu.org/licenses/>.
+
+import os, sys, redis
+
+from urllib2 import urlopen
+
+from cluster import Cluster
+from host import Host
+from route53 import Route53Zone
+from ec2 import EC2
+
+from events import Events
+
+# your amazon keys
+key = os.environ['EC2_KEY_ID']
+access = os.environ['EC2_SECRET_KEY']
+
+# what is the domain to work with
+name = os.environ['REDIS_NAME'].strip()
+zone_name = os.environ['HOSTED_ZONE_NAME'].rstrip('.')
+zone_id = os.environ['HOSTED_ZONE_ID']
+
+# the name (and identity) of the cluster (the master)
+cluster = "{0}.{1}".format(name, zone_name)
+
+# get/create the cluster environment
+cluster = Cluster(key, access, cluster)
+
+events = Events(key, access, cluster.name())
+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__':
+ try:
+ log('get Redis INFO', 'info')
+ info = r.info()
+
+ log('get the link_status', 'info')
+ if 'master_link_status' in info:
+ log('determine if our master is up', 'info')
+ if info['master_link_status'] == "up":
+ os.system('/bin/touch /var/run/redis/slave')
+
+ except Exception as e:
+ log('no redis yet?', 'info')
View
27 reslave.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Copyright (C) 2011, 2012 9apps B.V.
+#
+# This file is part of Redis for AWS.
+#
+# Redis for AWS is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Redis for AWS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Redis for AWS. If not, see <http://www.gnu.org/licenses/>.
+
+# pretty sad, but this is the easiest way to share
+# the configuration
+
+dirname=`dirname $0`
+
+source ${dirname}/config.sh
+# we only 'remaster' if we have been slave before
+python ${dirname}/reslave.py
Please sign in to comment.
Something went wrong with that request. Please try again.