Class: Chef::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/container.rb

Instance Method Summary collapse

Instance Method Details

#container_service(name, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/chef/container.rb', line 8

def container_service(name, &block)
  begin
    # Find the corresponding `service` resource and override the provider
    service_resource = resources("service[#{name}]")
    service_resource.provider = Chef::Provider::Service::ChefContainer

    # Setup the runit service
    runit_service = Chef::Resource::ContainerServiceRunit.new(service_resource.service_name, @run_context)
    runit_service.instance_eval(&block) if block
    runit_service.run_action(:enable)
  rescue Chef::Exceptions::ResourceNotFound => e
    Chef::Log.info "Resource service[#{name}] not found."
    raise e
  else
    # other exception
  ensure
    # always executed
  end
end