Notify the service defined in the included LWRP recipe

Is there a way to notify the service of a reboot, which is determined by LWRP enabled?

I wrote LWRP called "sidekiq", which installs a service like this, and it seems to work fine by itself.

service "#{new_resource.name}_sidekiq" do
  provider Chef::Provider::Service::Upstart
  action [ :enable ]
  subscribes :restart, "template[/etc/init/#{new_resource.name}_sidekiq.conf]", :immediately
end

The problem is that I am using a different recipe, which I use for deployment, and I need it to notify the service defined in LWRP. I currently have something like this

include_recipe "sidekiq"
deploy_revision my_dir do
  notifies :restart, "service[myapp_sidekiq]"
end

The problem is during compilation, the chef looks at this recipe and gives an error

ERROR: resource deploy_revision [my_dir] is configured to notify resource service [myapp_sidekiq] with a reboot, but service [myapp_sidekiq] cannot be found in the resource collection.

, , service 'myapp_sidekiq', . , sidekiq LWRP, myapp_sidekiq , , .

+4
2

, Chef, Tensibai inline run_context

script , , :nothing, .

service "myapp_sidekiq deploy notifier" do
  provider      Chef::Provider::Service::Upstart
  service_name  "myapp_sidekiq"
  action        :nothing
end

client.rb, Upstart , Chef - , systemd

Chef::Platform.set :platform => :yours, :resource => :service, :provider => Chef::Provider::Service::Upstart

, Chef 12, Chef , . - , - , - .

name, . service, , - - , , . , - . service_name

LWRP

, , , , Light Weight Resource and Provider, , :

service_myapp_sidekiq "deploy notifier" do
  action      :nothing
end

service_myapp_sidekiq "config subscriber" do
  action      :nothing
  subscribes  :restart, 'blah'
end

, LWRP action , , , , .

, , (, ).

def create_myapp_service name, action, options = {}
  s = Chef::Resource::Service.new "myapp service #{name}"
  s. service_name   "myapp_sidekiq"
  s.provider        Chef::Provider::Service::Upstart
  s.action          action
end

create_myapp_service "deploy", :nothing

, , , , .

TL;DR. service, :nothing .

+4

LWRP use_inline_resources run_context, LWRP resource_collection LWRP.

LWRP , , , .

, sidekiq LWRP, myapp_sidekiq , , .

, , deploy_revision / , (, , ..), , deploy_revision, .

+1

All Articles