chef-boneyard / httpd

DEPRECATED: Library cookbook with Apache httpd primitives
https://supermarket.chef.io/cookbooks/httpd
Apache License 2.0
39 stars 59 forks source link

default instance on centos7 - creates empty config file #24

Closed lanejlanej closed 9 years ago

lanejlanej commented 9 years ago

I tried switching up from version 0.1.5 to 0.2.6, and encountered a problem, with config file creation.

The resource in the recipe is as follows (which works with 0.1.5):

httpd_config 'drupal' do config_name 'drupal' instance 'default' source "drupal-web-env.conf.erb" action :create notifies :restart, 'httpd_service[default]' end

When this runs an /etc/http-default/conf.d directory is created, but the drupal.conf file is empty.

* directory[drupal :create /etc/httpd-default/conf.d] action create[2015-02-12T14:28:52+00:00] INFO: Processing directory[drupal :create /etc/httpd-default/conf.d] action create (/var/chef/cache/cookbooks/httpd/libraries/provider_httpd_config_rhel.rb line 19)

(up to date) * template[drupal :create /etc/httpd-default/conf.d/drupal.conf] action create[2015-02-12T14:28:52+00:00] INFO: Processing template[drupal :create /etc/httpd-default/conf.d/drupal.conf] action create (/var/chef/cache/cookbooks/httpd/libraries/provider_httpd_config_rhel.rb line 28) [2015-02-12T14:28:52+00:00] INFO: template[drupal :create /etc/httpd-default/conf.d/drupal.conf] created file /etc/httpd-default/conf.d/drupal.conf

  - create new file /etc/httpd-default/conf.d/drupal.conf
  ================================================================================
  Error executing action `create` on resource 'template[drupal :create /etc/httpd-default/conf.d/drupal.conf]'
  ================================================================================

  Chef::Mixin::Template::TemplateError
  ------------------------------------
  undefined method `[]' for nil:NilClass

  Resource Declaration:
  ---------------------
  # In /var/chef/cache/cookbooks/httpd/libraries/provider_httpd_config_rhel.rb

   28:           template "#{new_resource.name} :create /etc/#{apache_name}/conf.d/#{new_resource.config_name}.conf" do
   29:             path "/etc/#{apache_name}/conf.d/#{new_resource.config_name}.conf"
   30:             owner 'root'
   31:             group 'root'
   32:             mode '0644'
   33:             variables(new_resource.variables)
   34:             source new_resource.source
   35:             cookbook new_resource.cookbook
   36:             action :create
   37:           end
   38:         end

  Compiled Resource:
  ------------------
  # Declared in /var/chef/cache/cookbooks/httpd/libraries/provider_httpd_config_rhel.rb:28:in `block in <class:Rhel>'

I am not in a position to debug right now, as I had to switch back.

lanejlanej commented 9 years ago

If I try this on a vanilla system and exclude the additional config file element it fails to start the service instead:

Chef::Exceptions::Exec

  /bin/systemctl restart httpd-default returned 6, expected 0

When the above command is run manually: [root@ip-172-31-17-150 chef]# /bin/systemctl restart httpd-default Failed to issue method call: Unit httpd-default.service failed to load: No such file or directory.

someara commented 9 years ago

I can't seem to reproduce this.

Here's a test cookbook:

https://github.com/chef-cookbooks/httpd/blob/master/test/fixtures/cookbooks/httpd_config_test/recipes/default.rb

And serverspec:

https://github.com/chef-cookbooks/httpd/blob/master/test/integration/config/serverspec/rhel_spec.rb#L20

Perhaps your template source has an error in it?

-s

lanejlanej commented 9 years ago

Hi Sean, Thanks for looking in to this. Please go ahead and close this issue, as I can't reproduce the config file error in a stripped down environment. However, I am still seeing the following error:

================================================================================ Error executing action restart on resource 'httpd_service[default]'

Chef::Exceptions::Exec
----------------------
service[default :restart httpd-default] (/var/chef/cache/cookbooks/httpd/libraries/provider_httpd_service_rhel_systemd.rb line 74) had an error: Chef::Exceptions::Exec: /bin/systemctl restart httpd-default returned 6, expected 0

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/testbook/recipes/default.rb

 76: httpd_service 'default' do
 77:   action                  :create
 78:   keepalive               true
 79:   keepalivetimeout        '5'
 80:   maxkeepaliverequests    '500'
 81:   mpm                     'prefork'
 82:   version                 '2.4'
 83:   listen_ports            [ '80' ]
 84:   log_level               'warn'
 85: end
 86:

As there is no systemd service defined called httpd-default.service.

Do you want me to raise a separate issue for this?

Regard

John

lanejlanej commented 9 years ago

If the following change is made to provider_httpd_service_rhel_systemd.rb 18c18

< action :start do

      action :create do

things get a little further. ie. the sytemd config files are created etc. But, now the only content in /etc/httpd-default is conf.modules.d. And, the /usr/sbin/httpd-default link doesn't exist. Presumably because the :create action in the super class is getting run after the :create action in provider_httpd_service_rhel_systemd.rb.

lanejlanej commented 9 years ago

apologie, for formatting above... github magic.

lanejlanej commented 9 years ago

Sorry, realise how it is meant to work now, so flipped the action: statement above back to original, and put this in the recipe service entry

action [ :create, :start ]

Now, everything looks as it should. (But had to issue 'systemctl daemon-reload' to get the new service recognised).

BTW it still fails, as it isn't finding an MPM to use, but that is probably something in my config.

Apologies for wasting your time. But, have been pulling my hair out a bit about this.

lanejlanej commented 9 years ago

Tiny bit of added value from me.

Added execute "/bin/systemctl daemon-reload"

at line 56 in provider_httpd_service_rhel_systemd.rb

and all works perfectly.

someara commented 9 years ago

I still can't reproduce this... can you gist your entire recipe?

On Fri, Feb 13, 2015 at 9:31 AM, John Lane notifications@github.com wrote:

Tiny bit of added value from me.

Added execute "/bin/systemctl daemon-reload"

at line 56 in provider_httpd_service_rhel_systemd.rb

and all works perfectly.

— Reply to this email directly or view it on GitHub https://github.com/chef-cookbooks/httpd/issues/24#issuecomment-74261517.

lanejlanej commented 9 years ago

Hi Sean,

Gist at https://gist.github.com/lanejlanej/ad15b6e5bcfdfa73dd02

It may be something peculiar to my install of centos, but it seems to need that reload of the daemon to start (but not always, I think) or reload httpd-default.

Thanks for your help.

Regards

John

On Fri, Feb 13, 2015 at 2:44 PM, Sean OMeara notifications@github.com wrote:

I still can't reproduce this... can you gist your entire recipe?

On Fri, Feb 13, 2015 at 9:31 AM, John Lane notifications@github.com wrote:

Tiny bit of added value from me.

Added execute "/bin/systemctl daemon-reload"

at line 56 in provider_httpd_service_rhel_systemd.rb

and all works perfectly.

— Reply to this email directly or view it on GitHub <https://github.com/chef-cookbooks/httpd/issues/24#issuecomment-74261517 .

— Reply to this email directly or view it on GitHub https://github.com/chef-cookbooks/httpd/issues/24#issuecomment-74263522.

lanejlanej commented 9 years ago

Hi Sean, I will close this. I have worked out what was causing the problem. On my test runs I had been neglecting to delete /etc/systemd/system/multi-user.target.wants/httpd-default.service. As a consequence, I imagine, Chef said 'ah already a symlink in place, don't need to run "systemctl enable httpd-default" ' which means that the configuration doesn't get reloaded. So, my mistake. All works perfectly, sorry to have led you on wild goose chase.