Chef - 无法配置服务资源以在修改模板资源时重新加载

时间:2012-05-18 07:32:51

标签: chef

我完全没有获得安装服务的工作流程 未安装init.d文件。以下是我的安装方法 主管。同样在下面的boostrap错误。我有init.d 和配置文件作为模板。那么,我该如何调整逻辑来获得 厨师上班?

ec2-175-41-185-174.ap-southeast-1.compute.amazonaws.com [Thu, 17 May
2012 22:18:02 +0000] ERROR: Running exception handlers
ec2-175-41-185-174.ap-southeast-1.compute.amazonaws.com [Thu, 17 May
2012 22:18:02 +0000] FATAL: Saving node information to
/var/chef/cache/failed-run-data.json
ec2-175-41-185-174.ap-southeast-1.compute.amazonaws.com [Thu, 17 May
2012 22:18:02 +0000] ERROR: Exception handlers complete
ec2-175-41-185-174.ap-southeast-1.compute.amazonaws.com [Thu, 17 May
2012 22:18:02 +0000] FATAL: Stacktrace dumped to
/var/chef/cache/chef-stacktrace.out
ec2-175-41-185-174.ap-southeast-1.compute.amazonaws.com [Thu, 17 May
2012 22:18:02 +0000] FATAL: Errno::ENOENT: service[supervisord]
(supervisor::default line 23) had an error: Errno::ENOENT: No such
file or directory - /etc/init.d/supervisord restart



easy_install_package "supervisor" do
 action :install
end

template "/etc/supervisord.conf" do
 path "/etc/supervisord.conf"
 source "supervisord.conf.erb"
 owner "root"
 group "root"
 mode "0600"
end

template "/etc/init.d/supervisord" do
 path "/etc/init.d/supervisord"
 source "supervisord.erb"
 owner "root"
 group "root"
 mode "0755"
 #notifies :start, "service[supervisord]", :immediately
end

service "supervisord" do
 supports :restart => true, :start => true, :stop => true, :reload => true
 action [ :enable]
 subscribes :start, resources(:template =>
"/etc/init.d/supervisord"), :immediately
end

1 个答案:

答案 0 :(得分:0)

我认为您的问题是由于您在通知订阅属性中使用:immediate

当您使用:立即时,立即运行通知,这在某些情况下是有意义的,但在这种情况下,您通知的资源或您订阅的资源可能尚不存在厨师执行执行。

默认情况下,notifications are:delayed ,这意味着它们排队等待触发,并在Chef运行结束时执行。然后,它们可以传递到您要通知的services和其他资源。

对于上面的例子,我会修改如下内容:

template "/etc/supervisord.conf" do
 path "/etc/supervisord.conf"
 source "supervisord.conf.erb"
 owner "root"
 group "root"
 mode "0600"
 notifies :reload, "service[supervisord]", :delayed
end

template "/etc/init.d/supervisord" do
 path "/etc/init.d/supervisord"
 source "supervisord.erb"
 owner "root"
 group "root"
 mode "0755"
 notifies :reload, "service[supervisord]", :delayed
end

service "supervisord" do
 supports :restart => true, :start => true, :stop => true, :reload => true
 action :enable
end

以上代码执行以下操作:

  • 创建supervisord配置文件,然后通知supervisord在Chef运行结束时重新加载
  • 创建supervisord init.d脚本,然后通知supervisord在Chef运行结束时重新加载
  • 声明supervisord服务资源,支持重启,启动,停止和重新加载,并在任何运行之后启用它

有关Chef如何在运行列表中执行运行列表和cookbook的更多信息,请参阅The Chef Run或更早版本,但在某些方面仍然更清晰Anatomy of a Chef Run