2012-10-29 59 views
0

我已经创建了一个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。任何指针?

回答

1

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

restart = nameOfCookbook_nameOfResource "process" do 
    action :nothing 
end 

restart.run_action(:restart) 

我知道你已经设置初始化说重启,但我想通过行动:没有覆盖有这么要么迫使它按照上面的例子或模板部分中,当你想运行通知你想要的实际行动,这样

notifies :restart 

通过运行此myse如果我看到以下行为:只在资源上执行任何操作。不是在我的情况下会有的默认行为:停止

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

我从日志中了解到你已经告诉你的资源运行,但它的行动是:没有,所以它什么都不做。

+0

已编辑。通知:重启,而不是通知:运行应该工作 – PatrickWalker

+0

很酷,这工作。谢谢 :) – noMAD

0

确保您

notifies :run, 'nameOfCookbook_nameOfResource[process]' 

模板实际调度运行。 (例如使用调试输出)。因为如果文件已经存在那里,什么都不会做,所以重启也是如此。