Merge lp:~billy-olsen/charm-helpers/specify-restart-behavior-on-change into lp:charm-helpers

Proposed by Billy Olsen
Status: Work in progress
Proposed branch: lp:~billy-olsen/charm-helpers/specify-restart-behavior-on-change
Merge into: lp:charm-helpers
Diff against target: 54 lines (+23/-8)
1 file modified
charmhelpers/core/host.py (+23/-8)
To merge this branch: bzr merge lp:~billy-olsen/charm-helpers/specify-restart-behavior-on-change
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+247209@code.launchpad.net
To post a comment you must log in.
294. By Billy Olsen

Switch order of start stop and restart

Unmerged revisions

294. By Billy Olsen

Switch order of start stop and restart

293. By Billy Olsen

[wolsen,r=]

Adds the ability to control how the service restarts work. Allow
the charm developer to specify to restart, stop then start, reload,
etc and to do it selectively for the different services in the map.

Those services which are a list of strings will default to previous
behavior.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/core/host.py'
2--- charmhelpers/core/host.py 2015-01-21 11:30:54 +0000
3+++ charmhelpers/core/host.py 2015-01-21 19:29:44 +0000
4@@ -279,14 +279,16 @@
5 This function is used a decorator, for example::
6
7 @restart_on_change({
8- '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]
9+ '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume',
10+ {'haproxy': 'reload'} ]
11 })
12 def ceph_client_changed():
13 pass # your code here
14
15 In this example, the cinder-api and cinder-volume services
16 would be restarted if /etc/ceph/ceph.conf is changed by the
17- ceph_client_changed function.
18+ ceph_client_changed function. The haproxy service will be
19+ reloaded if the /etc/ceph/ceph.conf file is changed.
20 """
21 def wrap(f):
22 def wrapped_f(*args):
23@@ -299,12 +301,25 @@
24 if checksums[path] != file_hash(path):
25 restarts += restart_map[path]
26 services_list = list(OrderedDict.fromkeys(restarts))
27- if not stopstart:
28- for service_name in services_list:
29- service('restart', service_name)
30- else:
31- for action in ['stop', 'start']:
32- for service_name in services_list:
33+
34+ # Allow custom service reload mechanism to be specified
35+ # in the service definition.
36+ action_map = OrderedDict()
37+ for s in services_list:
38+ if isinstance(s, dict):
39+ action_map.update(s)
40+ elif not stopstart:
41+ action_map[s] = ['restart']
42+ else:
43+ action_map[s] = ['stop', 'start']
44+
45+ for service_name, actions in six.iteritems(action_map):
46+ for action in actions:
47+ # special case for reload so that if the service is
48+ # currently stopped, it will reload the service.
49+ if action == 'reload':
50+ service_reload(service_name)
51+ else:
52 service(action, service_name)
53 return wrapped_f
54 return wrap

Subscribers

People subscribed via source and target branches