厨师重量轻的资源提供商无法正常工作



我创建了一个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

资源

actions :restart
attribute :name, :kind_of => String, :name_attribute => true
def initialize(*args)
  super
  @action = :restart
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

厨师输出显示 foo bar ,但它在我的 bash 脚本中没有打印任何东西。因此,它不会运行bash。任何指针?

您不需要告诉实例运行操作:restart

喜欢

restart = nameOfCookbook_nameOfResource "process" do
  action :nothing
end
restart.run_action(:restart)

我知道您已经设置了初始化以说重新启动,但我认为通过操作:没有任何覆盖,所以要么迫使它在您想要的情况下按照上述示例或模板部分中的内部迫使它运行

notifies :restart

通过自己运行此操作,我看到了一个动作:仅在资源上没有执行。不是我的情况下的默认行为:停止

通过将通知更改为:停止它具有预期的行为。

我从日志中的理解是,您已经告诉您的资源运行,但它的操作是:什么都不做。

确保您的

notifies :run, 'nameOfCookbook_nameOfResource[process]'

在模板中实际计划运行。(例如,使用调试输出)。因为如果文件已经存在,什么也不会做,因此也重新启动。

最新更新