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
=== modified file 'charmhelpers/core/host.py'
--- charmhelpers/core/host.py 2015-01-21 11:30:54 +0000
+++ charmhelpers/core/host.py 2015-01-21 19:29:44 +0000
@@ -279,14 +279,16 @@
279 This function is used a decorator, for example::279 This function is used a decorator, for example::
280280
281 @restart_on_change({281 @restart_on_change({
282 '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume' ]282 '/etc/ceph/ceph.conf': [ 'cinder-api', 'cinder-volume',
283 {'haproxy': 'reload'} ]
283 })284 })
284 def ceph_client_changed():285 def ceph_client_changed():
285 pass # your code here286 pass # your code here
286287
287 In this example, the cinder-api and cinder-volume services288 In this example, the cinder-api and cinder-volume services
288 would be restarted if /etc/ceph/ceph.conf is changed by the289 would be restarted if /etc/ceph/ceph.conf is changed by the
289 ceph_client_changed function.290 ceph_client_changed function. The haproxy service will be
291 reloaded if the /etc/ceph/ceph.conf file is changed.
290 """292 """
291 def wrap(f):293 def wrap(f):
292 def wrapped_f(*args):294 def wrapped_f(*args):
@@ -299,12 +301,25 @@
299 if checksums[path] != file_hash(path):301 if checksums[path] != file_hash(path):
300 restarts += restart_map[path]302 restarts += restart_map[path]
301 services_list = list(OrderedDict.fromkeys(restarts))303 services_list = list(OrderedDict.fromkeys(restarts))
302 if not stopstart:304
303 for service_name in services_list:305 # Allow custom service reload mechanism to be specified
304 service('restart', service_name)306 # in the service definition.
305 else:307 action_map = OrderedDict()
306 for action in ['stop', 'start']:308 for s in services_list:
307 for service_name in services_list:309 if isinstance(s, dict):
310 action_map.update(s)
311 elif not stopstart:
312 action_map[s] = ['restart']
313 else:
314 action_map[s] = ['stop', 'start']
315
316 for service_name, actions in six.iteritems(action_map):
317 for action in actions:
318 # special case for reload so that if the service is
319 # currently stopped, it will reload the service.
320 if action == 'reload':
321 service_reload(service_name)
322 else:
308 service(action, service_name)323 service(action, service_name)
309 return wrapped_f324 return wrapped_f
310 return wrap325 return wrap

Subscribers

People subscribed via source and target branches