def service(manager, service): """ Create a service resource and subscribe to its dependencies. """ # Transform dependency list into a subscribe parameter. subscribe = [] def service_file(m, s, pathname): subscribe.append(File.ref(pathname)) walk.walk_service_files(b, manager, service, service_file=service_file) def service_package(m, s, pm, package): subscribe.append(Package.ref(package)) walk.walk_service_packages(b, manager, service, service_package=service_package) def service_source(m, s, dirname): subscribe.append(Exec.ref(b.sources[dirname])) walk.walk_service_sources(b, manager, service, service_source=service_source) kwargs = {'enable': True, 'ensure': 'running', 'subscribe': subscribe} if 'upstart' == manager: kwargs['provider'] = 'upstart' m['services'][manager].add(Service(service, **kwargs))
def service(manager, service): """ Create a service resource and subscribe to its dependencies. """ # Transform dependency list into a subscribes attribute. subscribe = [] def service_file(m, s, pathname): subscribe.append('cookbook_file[{0}]'.format(pathname)) # TODO Breaks inlining. walk.walk_service_files(b, manager, service, service_file=service_file) def service_package(m, s, pm, package): subscribe.append('package[{0}]'.format(package)) walk.walk_service_packages(b, manager, service, service_package=service_package) def service_source(m, s, dirname): subscribe.append('execute[{0}]'.format(b.sources[dirname])) walk.walk_service_sources(b, manager, service, service_source=service_source) subscribe = util.BareString('resources(' \ + ', '.join([repr(s) for s in subscribe]) + ')') kwargs = {'action': [[':enable', ':start']], 'subscribes': [':restart', subscribe]} if 'upstart' == manager: kwargs['provider'] = util.BareString( 'Chef::Provider::Service::Upstart') c.service(service, **kwargs)
def service(manager, service): """ Create a service resource and subscribe to its dependencies. """ # Transform dependency list into a subscribes attribute. # TODO Breaks inlining. subscribe = [] def service_file(m, s, pathname): f = b.files[pathname] if "120000" == f["mode"] or "120777" == f["mode"]: subscribe.append("link[{0}]".format(pathname)) else: subscribe.append("cookbook_file[{0}]".format(pathname)) walk.walk_service_files(b, manager, service, service_file=service_file) def service_package(m, s, pm, package): subscribe.append("package[{0}]".format(package)) walk.walk_service_packages(b, manager, service, service_package=service_package) def service_source(m, s, dirname): subscribe.append("execute[{0}]".format(b.sources[dirname])) walk.walk_service_sources(b, manager, service, service_source=service_source) subscribe = util.BareString("resources(" + ", ".join([repr(s) for s in subscribe]) + ")") kwargs = {"action": [[":enable", ":start"]], "subscribes": [":restart", subscribe]} if "upstart" == manager: kwargs["provider"] = util.BareString("Chef::Provider::Service::Upstart") c.service(service, **kwargs)