Skip to content

Instantly share code, notes, and snippets.

@spheromak
Created December 11, 2014 01:23
Show Gist options
  • Select an option

  • Save spheromak/45bfc4648f2e70ef0b88 to your computer and use it in GitHub Desktop.

Select an option

Save spheromak/45bfc4648f2e70ef0b88 to your computer and use it in GitHub Desktop.
# create_service builds a service resource we can notify in the given context
def create_service(ctx = nil)
ctx ||= @run_context
begin # this avoids resource cloning/recreation
ctx.resource_collection.find("service[#{new_resource.name}]")
rescue Chef::Exceptions::ResourceNotFound
Chef::Log.info "Creating 'service[#{new_resource.name}]' resource in context"
# define the service
s = Chef::Resource::Service.new(new_resource.name, ctx)
s.action :nothing
# add to contexts collection
ctx.resource_collection.insert(s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment