Only configure node name and restart service when required.
This commit is contained in:
parent
7b637e37e8
commit
990c809a05
|
@ -8,7 +8,7 @@ PACKAGES = ['pwgen', 'rabbitmq-server']
|
|||
|
||||
RABBITMQ_CTL = '/usr/sbin/rabbitmqctl'
|
||||
COOKIE_PATH = '/var/lib/rabbitmq/.erlang.cookie'
|
||||
|
||||
ENV_CONF = '/etc/rabbitmq/rabbitmq-env.conf'
|
||||
|
||||
def vhost_exists(vhost):
|
||||
cmd = [RABBITMQ_CTL, 'list_vhosts']
|
||||
|
@ -103,23 +103,35 @@ def set_node_name(name):
|
|||
# update or append RABBITMQ_NODENAME to environment config.
|
||||
# rabbitmq.conf.d is not present on all releases, so use or create
|
||||
# rabbitmq-env.conf instead.
|
||||
conf = '/etc/rabbitmq/rabbitmq-env.conf'
|
||||
|
||||
if not os.path.isfile(conf):
|
||||
utils.juju_log('INFO', '%s does not exist, creating.' % conf)
|
||||
with open(conf, 'wb') as out:
|
||||
if not os.path.isfile(ENV_CONF):
|
||||
utils.juju_log('INFO', '%s does not exist, creating.' % ENV_CONF)
|
||||
with open(ENV_CONF, 'wb') as out:
|
||||
out.write('RABBITMQ_NODENAME=%s\n' % name)
|
||||
return
|
||||
|
||||
out = []
|
||||
f = False
|
||||
for line in open(conf).readlines():
|
||||
for line in open(ENV_CONF).readlines():
|
||||
if line.strip().startswith('RABBITMQ_NODENAME'):
|
||||
f = True
|
||||
line = 'RABBITMQ_NODENAME=%s\n' % name
|
||||
out.append(line)
|
||||
if not f:
|
||||
out.append('RABBITMQ_NODENAME=%s\n' % name)
|
||||
utils.juju_log('INFO', 'Updating %s, RABBITMQ_NODENAME=%s' % (conf, name))
|
||||
with open(conf, 'wb') as conf:
|
||||
utils.juju_log('INFO', 'Updating %s, RABBITMQ_NODENAME=%s' %\
|
||||
(ENV_CONF, name))
|
||||
with open(ENV_CONF, 'wb') as conf:
|
||||
conf.write(''.join(out))
|
||||
|
||||
|
||||
def get_node_name():
|
||||
ENV_CONF = '/tmp/rabbitmq-env.conf'
|
||||
if not os.path.exists(ENV_CONF):
|
||||
return None
|
||||
node_name = None
|
||||
env_conf = open(ENV_CONF, 'r').readlines()
|
||||
node_name = None
|
||||
for l in env_conf:
|
||||
if l.startswith('RABBITMQ_NODENAME'):
|
||||
node_name = l.split('=')[1].strip()
|
||||
return node_name
|
||||
|
|
|
@ -130,11 +130,13 @@ def ha_joined():
|
|||
'ha_joined: No ceph relation yet, deferring.')
|
||||
return
|
||||
|
||||
# rabbit node-name need to match on all nodes.
|
||||
utils.juju_log('INFO', 'Stopping rabbitmq-server.')
|
||||
utils.stop('rabbitmq-server')
|
||||
|
||||
rabbit.set_node_name('%s@localhost' % SERVICE_NAME)
|
||||
name = '%s@localhost' % SERVICE_NAME
|
||||
if rabbit.get_node_name() != name:
|
||||
utils.juju_log('INFO', 'Stopping rabbitmq-server.')
|
||||
utils.stop('rabbitmq-server')
|
||||
rabbit.set_node_name('%s@localhost' % SERVICE_NAME)
|
||||
else:
|
||||
utils.juju_log('INFO', 'Node name already set to %s.' % name)
|
||||
|
||||
relation_settings = {}
|
||||
relation_settings['corosync_bindiface'] = corosync_bindiface
|
||||
|
|
Loading…
Reference in New Issue