[wolsen,r=]
Only restart the rabbitmq-server when config files change. Fixes Bug: 1409805
This commit is contained in:
@@ -37,6 +37,8 @@ from charmhelpers.contrib.peerstorage import (
|
|||||||
peer_retrieve
|
peer_retrieve
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
PACKAGES = ['rabbitmq-server', 'python-amqplib']
|
PACKAGES = ['rabbitmq-server', 'python-amqplib']
|
||||||
|
|
||||||
RABBITMQ_CTL = '/usr/sbin/rabbitmqctl'
|
RABBITMQ_CTL = '/usr/sbin/rabbitmqctl'
|
||||||
@@ -49,6 +51,24 @@ HOSTS_FILE = '/etc/hosts'
|
|||||||
|
|
||||||
_named_passwd = '/var/lib/charm/{}/{}.passwd'
|
_named_passwd = '/var/lib/charm/{}/{}.passwd'
|
||||||
|
|
||||||
|
# hook_contexts are used as a convenient mechanism to render
|
||||||
|
# templates logically, consider building a hook_context for
|
||||||
|
# template rendering so the charm doesn't concern itself with
|
||||||
|
CONFIG_FILES = OrderedDict([
|
||||||
|
(RABBITMQ_CONF, {
|
||||||
|
'hook_contexts': [],
|
||||||
|
'services': ['rabbitmq-server']
|
||||||
|
}),
|
||||||
|
(ENV_CONF, {
|
||||||
|
'hook_contexts': [],
|
||||||
|
'services': ['rabbitmq-server']
|
||||||
|
}),
|
||||||
|
(COOKIE_PATH, {
|
||||||
|
'hook_contexts': [],
|
||||||
|
'services': ['rabbitmq-server']
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def vhost_exists(vhost):
|
def vhost_exists(vhost):
|
||||||
try:
|
try:
|
||||||
@@ -441,3 +461,19 @@ def assert_charm_supports_ipv6():
|
|||||||
if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty":
|
if lsb_release()['DISTRIB_CODENAME'].lower() < "trusty":
|
||||||
raise Exception("IPv6 is not supported in the charms for Ubuntu "
|
raise Exception("IPv6 is not supported in the charms for Ubuntu "
|
||||||
"versions less than Trusty 14.04")
|
"versions less than Trusty 14.04")
|
||||||
|
|
||||||
|
def restart_map():
|
||||||
|
'''Determine the correct resource map to be passed to
|
||||||
|
charmhelpers.core.restart_on_change() based on the services configured.
|
||||||
|
|
||||||
|
:returns: dict: A dictionary mapping config file to lists of services
|
||||||
|
that should be restarted when file changes.
|
||||||
|
'''
|
||||||
|
_map = []
|
||||||
|
for f, ctxt in CONFIG_FILES.iteritems():
|
||||||
|
svcs = []
|
||||||
|
for svc in ctxt['services']:
|
||||||
|
svcs.append(svc)
|
||||||
|
if svcs:
|
||||||
|
_map.append((f, svcs))
|
||||||
|
return OrderedDict(_map)
|
||||||
@@ -50,7 +50,10 @@ from charmhelpers.core.hookenv import (
|
|||||||
UnregisteredHookError
|
UnregisteredHookError
|
||||||
)
|
)
|
||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
rsync, service_stop, service_restart, cmp_pkgrevno
|
cmp_pkgrevno,
|
||||||
|
restart_on_change,
|
||||||
|
rsync,
|
||||||
|
service_stop,
|
||||||
)
|
)
|
||||||
from charmhelpers.contrib.charmsupport.nrpe import NRPE
|
from charmhelpers.contrib.charmsupport.nrpe import NRPE
|
||||||
from charmhelpers.contrib.ssl.service import ServiceCA
|
from charmhelpers.contrib.ssl.service import ServiceCA
|
||||||
@@ -166,6 +169,7 @@ def amqp_changed(relation_id=None, remote_unit=None):
|
|||||||
|
|
||||||
|
|
||||||
@hooks.hook('cluster-relation-joined')
|
@hooks.hook('cluster-relation-joined')
|
||||||
|
@restart_on_change(rabbit.restart_map())
|
||||||
def cluster_joined(relation_id=None):
|
def cluster_joined(relation_id=None):
|
||||||
if config('prefer-ipv6'):
|
if config('prefer-ipv6'):
|
||||||
relation_settings = {'hostname': socket.gethostname(),
|
relation_settings = {'hostname': socket.gethostname(),
|
||||||
@@ -197,16 +201,13 @@ def cluster_joined(relation_id=None):
|
|||||||
if nodename:
|
if nodename:
|
||||||
log('forcing nodename=%s' % nodename)
|
log('forcing nodename=%s' % nodename)
|
||||||
# need to stop it under current nodename
|
# need to stop it under current nodename
|
||||||
service_stop('rabbitmq-server')
|
|
||||||
rabbit.update_rmq_env_conf(hostname='rabbit@%s' % nodename,
|
rabbit.update_rmq_env_conf(hostname='rabbit@%s' % nodename,
|
||||||
ipv6=config('prefer-ipv6'))
|
ipv6=config('prefer-ipv6'))
|
||||||
service_restart('rabbitmq-server')
|
|
||||||
|
|
||||||
if is_newer():
|
if is_newer():
|
||||||
log('cluster_joined: Relation greater.')
|
log('cluster_joined: Relation greater.')
|
||||||
return
|
return
|
||||||
|
|
||||||
rabbit.COOKIE_PATH = '/var/lib/rabbitmq/.erlang.cookie'
|
|
||||||
if not os.path.isfile(rabbit.COOKIE_PATH):
|
if not os.path.isfile(rabbit.COOKIE_PATH):
|
||||||
log('erlang cookie missing from %s' % rabbit.COOKIE_PATH,
|
log('erlang cookie missing from %s' % rabbit.COOKIE_PATH,
|
||||||
level=ERROR)
|
level=ERROR)
|
||||||
@@ -233,16 +234,8 @@ def cluster_changed():
|
|||||||
whitelist = [a for a in rdata.keys() if a not in blacklist]
|
whitelist = [a for a in rdata.keys() if a not in blacklist]
|
||||||
peer_echo(includes=whitelist)
|
peer_echo(includes=whitelist)
|
||||||
|
|
||||||
# sync cookie
|
# sync the cookie with peers if necessary
|
||||||
cookie = peer_retrieve('cookie')
|
update_cookie()
|
||||||
if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie:
|
|
||||||
log('Cookie already synchronized with peer.')
|
|
||||||
else:
|
|
||||||
log('Synchronizing erlang cookie from peer.')
|
|
||||||
rabbit.service('stop')
|
|
||||||
with open(rabbit.COOKIE_PATH, 'wb') as out:
|
|
||||||
out.write(cookie)
|
|
||||||
rabbit.service('start')
|
|
||||||
|
|
||||||
if is_relation_made('ha') and \
|
if is_relation_made('ha') and \
|
||||||
config('ha-vip-only') is False:
|
config('ha-vip-only') is False:
|
||||||
@@ -262,6 +255,18 @@ def cluster_changed():
|
|||||||
amqp_changed(relation_id=rid, remote_unit=unit)
|
amqp_changed(relation_id=rid, remote_unit=unit)
|
||||||
|
|
||||||
|
|
||||||
|
@restart_on_change(rabbit.restart_map())
|
||||||
|
def update_cookie():
|
||||||
|
# sync cookie
|
||||||
|
cookie = peer_retrieve('cookie')
|
||||||
|
if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie:
|
||||||
|
log('Cookie already synchronized with peer.')
|
||||||
|
else:
|
||||||
|
log('Synchronizing erlang cookie from peer.')
|
||||||
|
with open(rabbit.COOKIE_PATH, 'wb') as out:
|
||||||
|
out.write(cookie)
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('cluster-relation-departed')
|
@hooks.hook('cluster-relation-departed')
|
||||||
def cluster_departed():
|
def cluster_departed():
|
||||||
if is_relation_made('ha') and \
|
if is_relation_made('ha') and \
|
||||||
@@ -589,12 +594,8 @@ def configure_rabbit_ssl():
|
|||||||
open_port(ssl_port)
|
open_port(ssl_port)
|
||||||
|
|
||||||
|
|
||||||
def restart_rabbit_update_nrpe():
|
|
||||||
service_restart('rabbitmq-server')
|
|
||||||
update_nrpe_checks()
|
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('config-changed')
|
@hooks.hook('config-changed')
|
||||||
|
@restart_on_change(rabbit.restart_map())
|
||||||
def config_changed():
|
def config_changed():
|
||||||
if config('prefer-ipv6'):
|
if config('prefer-ipv6'):
|
||||||
rabbit.assert_charm_supports_ipv6()
|
rabbit.assert_charm_supports_ipv6()
|
||||||
@@ -616,9 +617,7 @@ def config_changed():
|
|||||||
chmod(RABBIT_DIR, 0o775)
|
chmod(RABBIT_DIR, 0o775)
|
||||||
|
|
||||||
if config('prefer-ipv6'):
|
if config('prefer-ipv6'):
|
||||||
service_stop('rabbitmq-server')
|
|
||||||
rabbit.update_rmq_env_conf(ipv6=config('prefer-ipv6'))
|
rabbit.update_rmq_env_conf(ipv6=config('prefer-ipv6'))
|
||||||
service_restart('rabbitmq-server')
|
|
||||||
|
|
||||||
if config('management_plugin') is True:
|
if config('management_plugin') is True:
|
||||||
rabbit.enable_plugin(MAN_PLUGIN)
|
rabbit.enable_plugin(MAN_PLUGIN)
|
||||||
@@ -633,15 +632,15 @@ def config_changed():
|
|||||||
ha_is_active_active = config("ha-vip-only")
|
ha_is_active_active = config("ha-vip-only")
|
||||||
|
|
||||||
if ha_is_active_active:
|
if ha_is_active_active:
|
||||||
restart_rabbit_update_nrpe()
|
update_nrpe_checks()
|
||||||
else:
|
else:
|
||||||
if is_elected_leader('res_rabbitmq_vip'):
|
if is_elected_leader('res_rabbitmq_vip'):
|
||||||
restart_rabbit_update_nrpe()
|
update_nrpe_checks()
|
||||||
else:
|
else:
|
||||||
log("hacluster relation is present but this node is not active"
|
log("hacluster relation is present but this node is not active"
|
||||||
" skipping update nrpe checks")
|
" skipping update nrpe checks")
|
||||||
else:
|
else:
|
||||||
restart_rabbit_update_nrpe()
|
update_nrpe_checks()
|
||||||
|
|
||||||
|
|
||||||
def pre_install_hooks():
|
def pre_install_hooks():
|
||||||
|
|||||||
Reference in New Issue
Block a user