Skip to content

Commit

Permalink
If provisioning of redis fails, we need to flag error and exit instead
Browse files Browse the repository at this point in the history
of continuing.

Change-Id: Icdedd8c157e9452edf30e17424f74c93f5fc81e1
Closes-Bug: #1458058
  • Loading branch information
Raj Reddy committed Aug 18, 2015
1 parent c59d47b commit d2d016d
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions fabfile/tasks/provision.py
Expand Up @@ -1126,43 +1126,44 @@ def setup_redis_server_node(*args):
for host_string in args:
# We need the redis to be listening on *, comment bind line
with settings(host_string=host_string):
with settings(warn_only=True):
if detect_ostype() == 'ubuntu':
redis_svc_name = 'redis-server'
redis_conf_file = '/etc/redis/redis.conf'
do_chkconfig = False
check_svc_started = True
else:
redis_svc_name = 'redis'
redis_conf_file = '/etc/redis.conf'
do_chkconfig = True
check_svc_started = False
if detect_ostype() == 'ubuntu':
redis_svc_name = 'redis-server'
redis_conf_file = '/etc/redis/redis.conf'
do_chkconfig = False
check_svc_started = True
else:
redis_svc_name = 'redis'
redis_conf_file = '/etc/redis.conf'
do_chkconfig = True
check_svc_started = False

with settings(warn_only=True):
sudo("service %s stop" % (redis_svc_name))
sudo("sed -i -e '/^[ ]*bind/s/^/#/' %s" % (redis_conf_file))
# Set the lua-time-limit to 15000 milliseconds
sudo("sed -i -e 's/lua-time-limit.*/lua-time-limit 15000/' %s" % (redis_conf_file))
# If redis passwd specified, add that to the conf file
if get_redis_password():
sudo("sed -i '/^# requirepass/ c\ requirepass %s' %s" % (get_redis_password(), redis_conf_file))
# Disable persistence
dbfilename = sudo("grep '^dbfilename' %s | awk '{print $2}'" % (redis_conf_file))
if dbfilename:
dbdir = sudo("grep '^dir' %s | awk '{print $2}'" % (redis_conf_file))
if dbdir:
sudo("rm -f %s/%s" % (dbdir, dbfilename))
sudo("sed -i -e '/^[ ]*save/s/^/#/' %s" % (redis_conf_file))
sudo("sed -i -e '/^[ ]*dbfilename/s/^/#/' %s" % (redis_conf_file))
if do_chkconfig:
sudo("chkconfig %s on" % (redis_svc_name))
sudo("service %s start" % (redis_svc_name))
if check_svc_started:
# Check if the redis-server is running, if not, issue start again
count = 1
sudo("sed -i -e '/^[ ]*bind/s/^/#/' %s" % (redis_conf_file))
# Set the lua-time-limit to 15000 milliseconds
sudo("sed -i -e 's/lua-time-limit.*/lua-time-limit 15000/' %s" % (redis_conf_file))
# If redis passwd specified, add that to the conf file
if get_redis_password():
sudo("sed -i '/^# requirepass/ c\ requirepass %s' %s" % (get_redis_password(), redis_conf_file))
# Disable persistence
dbfilename = sudo("grep '^dbfilename' %s | awk '{print $2}'" % (redis_conf_file))
if dbfilename:
dbdir = sudo("grep '^dir' %s | awk '{print $2}'" % (redis_conf_file))
if dbdir:
sudo("rm -f %s/%s" % (dbdir, dbfilename))
sudo("sed -i -e '/^[ ]*save/s/^/#/' %s" % (redis_conf_file))
sudo("sed -i -e '/^[ ]*dbfilename/s/^/#/' %s" % (redis_conf_file))
if do_chkconfig:
sudo("chkconfig %s on" % (redis_svc_name))
sudo("service %s start" % (redis_svc_name))
if check_svc_started:
# Check if the redis-server is running, if not, issue start again
count = 1
with settings(warn_only=True):
while sudo("service %s status | grep not" % (redis_svc_name)).succeeded:
count += 1
if count > 10:
break
raise RuntimeError("redis-server did not start successfully")
sleep(1)
sudo("service %s restart" % (redis_svc_name))
#end setup_redis_server_node
Expand Down

0 comments on commit d2d016d

Please sign in to comment.