def restart_on_change(self):
"""Restart the services in the self.restart_map{} attribute if any of
the files identified by the keys changes for the wrapped call.
This function is a @decorator that checks if the wrapped function
changes any of the files identified by the keys in the
self.restart_map{} and, if they change, restarts the services in the
corresponding list.
"""
checksums = {path: ch_host.path_hash(path)
for path in self.full_restart_map.keys()}
yield
restarts = []
for path in self.full_restart_map:
if ch_host.path_hash(path) != checksums[path]:
restarts += self.full_restart_map[path]
services_list = list(collections.OrderedDict.fromkeys(restarts).keys())
for service_name in services_list:
ch_host.service_stop(service_name)
for service_name in services_list:
ch_host.service_start(service_name)
评论列表
文章目录