Provide both restart and stop/start functionality

This commit is contained in:
Ante Karamatic 2014-02-16 19:44:30 +01:00
parent 3c2fa8b8b5
commit 2a6124ec60
2 changed files with 11 additions and 7 deletions

View File

@ -194,7 +194,7 @@ def file_hash(path):
return None
def restart_on_change(restart_map):
def restart_on_change(restart_map, stopstart=False):
"""Restart services based on configuration files changing
This function is used a decorator, for example
@ -219,10 +219,14 @@ def restart_on_change(restart_map):
for path in restart_map:
if checksums[path] != file_hash(path):
restarts += restart_map[path]
for service_name in list(OrderedDict.fromkeys(restarts)):
service('stop', service_name)
for service_name in list(OrderedDict.fromkeys(restarts)):
service('start', service_name)
services_list = list(OrderedDict.fromkeys(restarts))
if not stopstart:
for service_name in services_list:
service('restart', service_name)
else:
for action in ['stop', 'start']:
for service_name in services_list:
service(action, service_name)
return wrapped_f
return wrap

View File

@ -94,7 +94,7 @@ def install():
@hooks.hook('config-changed')
@restart_on_change(restart_map())
@restart_on_change(restart_map(), stopstart=True)
def config_changed():
if openstack_upgrade_available('nova-common'):
do_openstack_upgrade(configs=CONFIGS)
@ -333,7 +333,7 @@ def quantum_joined(rid=None):
@hooks.hook('cluster-relation-changed',
'cluster-relation-departed')
@restart_on_change(restart_map())
@restart_on_change(restart_map(), stopstart=True)
def cluster_changed():
CONFIGS.write_all()