2

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

我正在从自定义 solo.rb 配方调用的自定义资源 (LWRP) 内部调用 Apache2 资源 web_app。

    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 标头] 配置为通知资源服务 [apache2]重新加载操作,但在资源集合中找不到 service[apache2]。execute[a2enmod headers] 在 /tmp/kitchen/cache/cookbooks/apache2/definitions/apache_module.rb:35:in `block in from_file' 中定义

但是,当我在此处(第 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 上都失败了。

4

1 回答 1

1

这是一个已知问题,目前几乎没有解决方法。问题是使用新的自定义资源系统会强制执行use_inline_resources模式,除此之外,这是 99% 的好主意。该模式在自定义资源中创建了一个隔离的运行上下文,因此它无法看到其他资源的“外部”以用于通知目的。Poise 助手库提供了一些工具来解决这个问题,但是对于 Chef 核心,唯一的主要解决方法是超级不受支持(即,如果没有主要版本,这可能会中断):

web_app url do
  # ...
  notifies :reload, Chef.run_context.resource_collection.find('service[apache2]')
end
于 2016-02-24T18:58:49.600 回答