Browse Source

Improved plumgrid service restarts

tags/14.04-eol
Junaid Ali 3 years ago
parent
commit
9f71449b32
2 changed files with 18 additions and 9 deletions
  1. 3
    9
      hooks/pg_gw_hooks.py
  2. 15
    0
      hooks/pg_gw_utils.py

+ 3
- 9
hooks/pg_gw_hooks.py View File

@@ -14,8 +14,6 @@ from charmhelpers.core.hookenv import (
14 14
     config,
15 15
 )
16 16
 
17
-from charmhelpers.core.host import service_running
18
-
19 17
 from charmhelpers.fetch import (
20 18
     apt_install,
21 19
     configure_sources,
@@ -24,7 +22,6 @@ from charmhelpers.fetch import (
24 22
 from pg_gw_utils import (
25 23
     register_configs,
26 24
     ensure_files,
27
-    restart_pg,
28 25
     restart_map,
29 26
     stop_pg,
30 27
     determine_packages,
@@ -35,6 +32,7 @@ from pg_gw_utils import (
35 32
     fabric_interface_changed,
36 33
     load_iptables,
37 34
     restart_on_change,
35
+    restart_on_stop,
38 36
     director_cluster_ready
39 37
 )
40 38
 
@@ -71,6 +69,8 @@ def plumgrid_changed():
71 69
 
72 70
 
73 71
 @hooks.hook('config-changed')
72
+@restart_on_stop()
73
+@restart_on_change(restart_map())
74 74
 def config_changed():
75 75
     '''
76 76
     This hook is run when a config parameter is changed.
@@ -83,10 +83,6 @@ def config_changed():
83 83
     if charm_config.changed('fabric-interfaces'):
84 84
         if not fabric_interface_changed():
85 85
             log("Fabric interface already set")
86
-        else:
87
-            stop_pg()
88
-    if charm_config.changed('external-interfaces'):
89
-        stop_pg()
90 86
     if (charm_config.changed('install_sources') or
91 87
         charm_config.changed('plumgrid-build') or
92 88
         charm_config.changed('install_keys') or
@@ -100,8 +96,6 @@ def config_changed():
100 96
             load_iovisor()
101 97
     ensure_mtu()
102 98
     CONFIGS.write_all()
103
-    if not service_running('plumgrid'):
104
-        restart_pg()
105 99
 
106 100
 
107 101
 @hooks.hook('upgrade-charm')

+ 15
- 0
hooks/pg_gw_utils.py View File

@@ -393,6 +393,19 @@ def director_cluster_ready():
393 393
     return True if dirs_count == 1 or dirs_count == 3 else False
394 394
 
395 395
 
396
+def 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
+
396 409
 def restart_on_change(restart_map):
397 410
     """
398 411
     Restart services based on configuration files changing
@@ -403,6 +416,8 @@ def restart_on_change(restart_map):
403 416
             f(*args, **kwargs)
404 417
             for path in restart_map:
405 418
                 if path_hash(path) != checksums[path]:
419
+                    if path == PG_IFCS_CONF:
420
+                        ensure_files()
406 421
                     restart_pg()
407 422
                     break
408 423
         return wrapped_f

Loading…
Cancel
Save