当从自定义资源调用时,Chef2,Apache2 cookbook ressource无法找到服务[apache2]

时间:2016-02-24 16:09:14

标签: apache service chef cookbook lwrp

在我的自定义厨师食谱中(位于https://github.com/sanguis/chef-omeka/tree/lwrp)。

我从自定义资源(LWRP)中调用Apache2资源web_app,该资源是从自定义solo.rb配方调用的。

    include_recipe 'apache2' 
web_app url do
  server_name url
  server_aliases aliaes
  cookbook_name 'apache2'
  docroot dir
  allow_override 'All'
  directory_index 'false'
  # notifies :reload, 'service[apache2]', :delayed
end

这会返回错误:

  

[#] [2016-02-23T23:02:31 + 00:00]致命:如果您提交错误报告,请提供stacktrace.out文件的内容

     

[#] [2016-02-23T23:02:31 + 00:00]错误:instanceomeka.dev出错:Chef :: Exceptions :: ResourceNotFound:资源执行[a2enmod headers]配置为通知资源服务[apache2]带有动作重新加载,但在资源集合中找不到服务[apache2]。执行[a2enmod headers]在/tmp/kitchen/cache/cookbooks/apache2/definitions/apache_module.rb:35:在from_file'

中的块中定义

但是,当我直接从自定义食谱here(第126行)内部调用相同的资源时,它可以正常工作。

我的运行列表如下:

   #      - recipe[build-essential]
  - recipe[php::default]
  - recipe[apache2]
  - recipe[apache2::mod_rewrite]
    # - recipe[apache2::mod_expires]
  - recipe[apache2::mod_ssl]
  - recipe[apache2::mod_php5]
  - recipe[omeka::default]
  - recipe[omeka::solo]
attributes:    #      - recipe[build-essential]
  - recipe[php::default]
  - recipe[apache2]
  - recipe[apache2::mod_rewrite]
    # - recipe[apache2::mod_expires]
  - recipe[apache2::mod_ssl]
  - recipe[apache2::mod_php5]
  - recipe[omeka::default]
  - recipe[omeka::solo]
attributes: 
  machine_fqdn: omeka.dev
  machine_fqdn_as_hostname: true
  apache2:
    listen_ports: ["80", "443"]

  machine_fqdn: omeka.dev
  machine_fqdn_as_hostname: true
  apache2:
    listen_ports: ["80", "443"]

ubuntu 14.04和centos7都失败了。

1 个答案:

答案 0 :(得分:1)

这是一个众所周知的问题,暂时没有解决方法。问题是使用新的自定义资源系统会强制执行use_inline_resources模式,除此之外,这是一个很好的主意。该模式在自定义资源中创建了一个独立的运行上下文,因此出于通知的目的,它无法看到“out”到其他资源。 Poise帮助程序库提供了一些解决此问题的工具,但使用Chef核心时,唯一的主要解决方法是超级不受支持(即,如果没有主要版本,这可能会中断):

web_app url do
  # ...
  notifies :reload, Chef.run_context.resource_collection.find('service[apache2]')
end