Chef infra chef轻型资源提供程序不工作

Chef infra chef轻型资源提供程序不工作,chef-infra,Chef Infra,我已经创建了一个LWRP(我第一次),但它似乎没有按要求工作。我不确定我是否遗漏了什么或做错了什么。opscode文档非常糟糕。我已经在下面显示了我的代码: 提供商 puts "FOO" def restart_process @svc = Chef::Resource::RestartProcesses.new(new_resource.name) Chef::Log.debug("Restarting services according to the box") notifi

我已经创建了一个LWRP(我第一次),但它似乎没有按要求工作。我不确定我是否遗漏了什么或做错了什么。opscode文档非常糟糕。我已经在下面显示了我的代码:

提供商

puts "FOO"

def restart_process
  @svc = Chef::Resource::RestartProcesses.new(new_resource.name)
  Chef::Log.debug("Restarting services according to the box")
  notifies :run, resources(:execute => 'restart-storm')
end

puts "BAR"

action :restart do

  execute 'restart-process' do
    command <<-EOH
      echo "-------Executing restart process--------"
      #Some bash code
    EOH
  end
end
调用资源的配方

template "#{install_dir}/####Something" do
  source "someSource.erb"
  variables(
    ###Some variables
  )

  notifies :run, 'nameOfCookbook_nameOfResource[process]'
end

nameOfCookbook_nameOfResource "process" do
  action :nothing
end

chef输出显示FOO-BAR,但它不会在我的bash脚本中打印任何内容。所以它不会运行bash。有指针吗?

您不需要告诉实例运行操作:重新启动吗

我知道您已将initialize设置为restart,但我认为passing action:没有任何内容会覆盖它,因此,您可以按照上面的示例在需要时强制它运行,或者在模板部分中通知您所需的实际操作

notifies :restart
通过自己运行这个,我看到了一个操作:仅在资源上没有执行任何操作。而不是我的默认行为:停止

通过将通知更改为:stop,它具有预期的行为

我从日志中了解到,您已经告诉您的资源运行,但它的操作是:什么也不做,所以它什么也不做

确保您的

notifies :run, 'nameOfCookbook_nameOfResource[process]'

在实际计划运行的模板中。(例如,使用调试输出)。因为如果文件已经存在,则不会执行任何操作,因此也会重新启动。

。通知:重新启动而不是通知:运行应该可以工作
notifies :restart
notifies :run, 'nameOfCookbook_nameOfResource[process]'