summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunaid Ali <junaidali@plumgrid.com>2016-03-28 19:19:54 +0500
committerJunaid Ali <junaidali@plumgrid.com>2016-03-28 19:19:54 +0500
commit9f71449b3234796e11bb3a9cec95156be43aeb5b (patch)
tree564a057fa8bd101c6b7e5893cfd6cf897a59d72b
parente74a4757fbfea9ef05f6fca2313214311b9ab7e8 (diff)
Improved plumgrid service restarts
-rwxr-xr-xhooks/pg_gw_hooks.py12
-rw-r--r--hooks/pg_gw_utils.py15
2 files changed, 18 insertions, 9 deletions
diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py
index ad020ed..1d3f87d 100755
--- a/hooks/pg_gw_hooks.py
+++ b/hooks/pg_gw_hooks.py
@@ -14,8 +14,6 @@ from charmhelpers.core.hookenv import (
14 config, 14 config,
15) 15)
16 16
17from charmhelpers.core.host import service_running
18
19from charmhelpers.fetch import ( 17from charmhelpers.fetch import (
20 apt_install, 18 apt_install,
21 configure_sources, 19 configure_sources,
@@ -24,7 +22,6 @@ from charmhelpers.fetch import (
24from pg_gw_utils import ( 22from pg_gw_utils import (
25 register_configs, 23 register_configs,
26 ensure_files, 24 ensure_files,
27 restart_pg,
28 restart_map, 25 restart_map,
29 stop_pg, 26 stop_pg,
30 determine_packages, 27 determine_packages,
@@ -35,6 +32,7 @@ from pg_gw_utils import (
35 fabric_interface_changed, 32 fabric_interface_changed,
36 load_iptables, 33 load_iptables,
37 restart_on_change, 34 restart_on_change,
35 restart_on_stop,
38 director_cluster_ready 36 director_cluster_ready
39) 37)
40 38
@@ -71,6 +69,8 @@ def plumgrid_changed():
71 69
72 70
73@hooks.hook('config-changed') 71@hooks.hook('config-changed')
72@restart_on_stop()
73@restart_on_change(restart_map())
74def config_changed(): 74def config_changed():
75 ''' 75 '''
76 This hook is run when a config parameter is changed. 76 This hook is run when a config parameter is changed.
@@ -83,10 +83,6 @@ def config_changed():
83 if charm_config.changed('fabric-interfaces'): 83 if charm_config.changed('fabric-interfaces'):
84 if not fabric_interface_changed(): 84 if not fabric_interface_changed():
85 log("Fabric interface already set") 85 log("Fabric interface already set")
86 else:
87 stop_pg()
88 if charm_config.changed('external-interfaces'):
89 stop_pg()
90 if (charm_config.changed('install_sources') or 86 if (charm_config.changed('install_sources') or
91 charm_config.changed('plumgrid-build') or 87 charm_config.changed('plumgrid-build') or
92 charm_config.changed('install_keys') or 88 charm_config.changed('install_keys') or
@@ -100,8 +96,6 @@ def config_changed():
100 load_iovisor() 96 load_iovisor()
101 ensure_mtu() 97 ensure_mtu()
102 CONFIGS.write_all() 98 CONFIGS.write_all()
103 if not service_running('plumgrid'):
104 restart_pg()
105 99
106 100
107@hooks.hook('upgrade-charm') 101@hooks.hook('upgrade-charm')
diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py
index 5bf695c..3af1926 100644
--- a/hooks/pg_gw_utils.py
+++ b/hooks/pg_gw_utils.py
@@ -393,6 +393,19 @@ def director_cluster_ready():
393 return True if dirs_count == 1 or dirs_count == 3 else False 393 return True if dirs_count == 1 or dirs_count == 3 else False
394 394
395 395
396def restart_on_stop():
397 """
398 Restart Plumgrid service if it is stopped by any config parameter
399 """
400 def wrap(f):
401 def wrapped_f(*args, **kwargs):
402 f(*args, **kwargs)
403 if not service_running('plumgrid'):
404 restart_pg()
405 return wrapped_f
406 return wrap
407
408
396def restart_on_change(restart_map): 409def restart_on_change(restart_map):
397 """ 410 """
398 Restart services based on configuration files changing 411 Restart services based on configuration files changing
@@ -403,6 +416,8 @@ def restart_on_change(restart_map):
403 f(*args, **kwargs) 416 f(*args, **kwargs)
404 for path in restart_map: 417 for path in restart_map:
405 if path_hash(path) != checksums[path]: 418 if path_hash(path) != checksums[path]:
419 if path == PG_IFCS_CONF:
420 ensure_files()
406 restart_pg() 421 restart_pg()
407 break 422 break
408 return wrapped_f 423 return wrapped_f