chef-boneyard / knife-container

DEPRECATED: Container support for Chef's Knife Command
Apache License 2.0
57 stars 11 forks source link

Error enabling service with apache2 in chef/centos-7 #47

Closed mlamy closed 9 years ago

mlamy commented 9 years ago

Hi,

I'm trying to build an apache2 container with centos7 image. I started with init: knife container docker init siag/apache2 -r 'recipe[apache2]' -f chef/centos-7 -b

After that I changed first-boot.json to:

{ "run_list": [ "recipe[apache2]" ], "container_service": { "apache2": { "command": "/usr/sbin/httpd -k start" } } }

And finally I tried to build the container with: knife container docker build siag/apache2 -b

Unfortunately I can't figure out why is not working. Can someone please help me understand why the service can't be enabled ?

Thank you,

Miguel

[2014-10-15T10:58:45+01:00] INFO: Provider for service[apache2] has been replaced with Chef::Provider::ContainerService::Runit

[2014-10-15T10:58:51+01:00] INFO: package[apache2] installing httpd-2.4.6-18.el7.centos from updates repository [2014-10-15T10:59:29+01:00] INFO: Processing service[apache2] action enable (apache2::default line 24)

Error executing action enable on resource 'service[apache2]'

NoMethodError

undefined method `[]' for nil:NilClass

Resource Declaration:

In /var/chef/cache/cookbooks/apache2/recipes/default.rb

24: service 'apache2' do 25: service_name node['apache']['package'] 26: case node['platform_family'] 27: when 'rhel' 28: reload_command '/sbin/service httpd graceful' 29: when 'debian' 30: provider Chef::Provider::Service::Debian 31: when 'arch' 32: service_name 'httpd' 33: end 34: supports [:start, :restart, :reload, :status]

Compiled Resource:

Declared in /var/chef/cache/cookbooks/apache2/recipes/default.rb:24:in `from_file'

service("apache2") do provider Chef::Provider::ContainerService::Runit action [:enable, :start] supports {:restart=>true, :reload=>true, :status=>true, :start=>true} retries 0 retry_delay 2 guard_interpreter :default service_name "httpd" pattern "apache2" reload_command "/sbin/service httpd graceful" cookbook_name "apache2" recipe_name "default" only_if "/usr/sbin/httpd -t" end

[2014-10-15T10:59:29+01:00] INFO: Running queued delayed notifications before re-raising exception [2014-10-15T10:59:29+01:00] ERROR: Running exception handlers [2014-10-15T10:59:29+01:00] ERROR: Exception handlers complete [2014-10-15T10:59:29+01:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out [2014-10-15T10:59:29+01:00] ERROR: service[apache2](apache2::default line 24) had an error: NoMethodError: undefined method `[]' for nil:NilClass [2014-10-15T10:59:29+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) [2014-10-15T10:59:29+01:00] INFO: Deleting client key... 2014/10/15 10:59:35 The command [/bin/sh -c chef-init --bootstrap] returned a non-zero code: 1

tduffield commented 9 years ago

Check out https://github.com/opscode/knife-container/issues/44 for the solution.

mlamy commented 9 years ago

Hi Tom. Thank you for you quick reply. I missed #44 completely...sorry.

I changed first-boot.json to:

{ "run_list": [ "recipe[apache2]" ], "container_service": { "httpd": { "command": "/usr/sbin/httpd -DFOREGROUND" } } }

Unfortunately with that name change I don't see runit change service line - Provider for service[apache2] has been replaced with Chef::Provider::ContainerService::Runit in log:

[2014-10-15T17:44:10+01:00] INFO: Storing updated cookbooks/pacman/CONTRIBUTING in the cache. [2014-10-15T17:44:11+01:00] INFO: Processing package[apache2] action install (apache2::default line 20) [2014-10-15T17:44:16+01:00] INFO: package[apache2] installing httpd-2.4.6-18.el7.centos from updates repository [2014-10-15T17:44:40+01:00] INFO: Processing service[apache2] action enable (apache2::default line 24)

And I get:

Chef::Exceptions::Service

service[apache2]: unable to locate the init.d script!

service("apache2") do action [:enable, :start] supports {:restart=>true, :reload=>true, :status=>true, :start=>true} retries 0 retry_delay 2 guard_interpreter :default service_name "httpd" pattern "apache2" reload_command "/sbin/service httpd graceful" cookbook_name "apache2" recipe_name "default" only_if "/usr/sbin/httpd -t" end

Instead of

service("apache2") do provider Chef::Provider::ContainerService::Runit action [:enable, :start] supports {:restart=>true, :reload=>true, :status=>true, :start=>true} retries 0 retry_delay 2 guard_interpreter :default service_name "httpd" pattern "apache2" reload_command "/usr/sbin/service httpd graceful" cookbook_name "apache2" recipe_name "default" end

am I still missing something ?

Thanks for your patience. Miguel

tduffield commented 9 years ago

not that I can see. After you changed the first-boot.json, what command did you run?

tduffield commented 9 years ago

Also, it would be very helpful if you could provide the full output of your command in a formatted way (via a gist or pastebin).

mlamy commented 9 years ago

Hi Tom. The full log is at: https://gist.github.com/mlamy/7e0857139acc6773978d.

My knife-container version is 0.2.4.

I executed: knife container docker init siag/apache2 -r 'recipe[apache2]' -f chef/centos-7 -b --force and after that I changed first-boot.json and executed knife container docker build siag/apache2 -b --force

I tried wih centos-6 and it worked :-) . I'm guessing that this problem may be related how centos 7 start services. It uses systemctl and not /etc/init.d as before. If my guessing is correct can you suggest an workaround for this problem ?

Thank you. Miguel