我已经创建了一个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。有什么指针吗?
答案 0 :(得分:1)
您是否需要告诉实例运行操作:restart
喜欢
restart = nameOfCookbook_nameOfResource "process" do
action :nothing
end
restart.run_action(:restart)
我知道你已经将初始化设置为重新启动,但我认为传递操作:没有任何覆盖,因此要么按照上面的示例强制它运行,要么在模板部分内通知你想要的实际操作
notifies :restart
通过自己运行,我看到了一个动作:没有在资源上执行任何操作。不是我的情况下的默认行为:停止
通过将通知更改为:停止它具有预期的行为。
我从日志中了解到你已经告诉你的资源要运行,但它的行动是:什么也没做什么。
答案 1 :(得分:0)
确保你的
notifies :run, 'nameOfCookbook_nameOfResource[process]'
实际计划运行的模板中的。 (例如,使用调试输出)。因为如果文件已经存在,那么什么都不会完成,所以重启也是如此。