restart_on_change
This commit is contained in:
parent
d9713c8c21
commit
fa4588b0e3
@ -36,7 +36,8 @@ from pg_dir_utils import (
|
||||
add_lcm_key,
|
||||
post_pg_license,
|
||||
fabric_interface_changed,
|
||||
load_iptables
|
||||
load_iptables,
|
||||
restart_on_change
|
||||
)
|
||||
|
||||
hooks = Hooks()
|
||||
@ -74,7 +75,7 @@ def plumgrid_joined(relation_id=None):
|
||||
'''
|
||||
opsvm_ip = config('opsvm-ip')
|
||||
if opsvm_ip == '127.0.0.1':
|
||||
return 1
|
||||
pass
|
||||
elif not is_ip(opsvm_ip):
|
||||
raise ValueError('Incorrect IP specified')
|
||||
else:
|
||||
@ -138,13 +139,13 @@ def start():
|
||||
|
||||
|
||||
@hooks.hook('upgrade-charm')
|
||||
@restart_on_change(restart_map())
|
||||
def upgrade_charm():
|
||||
'''
|
||||
This hook is run when the charm is upgraded
|
||||
'''
|
||||
ensure_mtu()
|
||||
CONFIGS.write_all()
|
||||
restart_pg()
|
||||
|
||||
|
||||
@hooks.hook('stop')
|
||||
|
@ -12,7 +12,6 @@ from socket import gethostname as get_unit_hostname
|
||||
from copy import deepcopy
|
||||
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
|
||||
from charmhelpers.contrib.openstack import templating
|
||||
from charmhelpers.core.host import set_nic_mtu
|
||||
from charmhelpers.contrib.storage.linux.ceph import modprobe
|
||||
from charmhelpers.core.hookenv import (
|
||||
log,
|
||||
@ -30,7 +29,9 @@ from charmhelpers.contrib.network.ip import (
|
||||
from charmhelpers.core.host import (
|
||||
service_start,
|
||||
service_stop,
|
||||
service_running
|
||||
service_running,
|
||||
path_hash,
|
||||
set_nic_mtu
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
apt_cache,
|
||||
@ -406,3 +407,19 @@ def get_cidr_from_iface(interface):
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def restart_on_change(restart_map):
|
||||
"""
|
||||
Restart services based on configuration files changing
|
||||
"""
|
||||
def wrap(f):
|
||||
def wrapped_f(*args, **kwargs):
|
||||
checksums = {path: path_hash(path) for path in restart_map}
|
||||
f(*args, **kwargs)
|
||||
for path in restart_map:
|
||||
if path_hash(path) != checksums[path]:
|
||||
restart_pg()
|
||||
break
|
||||
return wrapped_f
|
||||
return wrap
|
||||
|
Loading…
x
Reference in New Issue
Block a user