Closed snayakie closed 9 years ago
So undefined method []' for nil:NilClass
typically means that you are referencing a node attribute that has not been defined. Can you provide me with the knife container docker init
command you used as well as the contents of your first-boot.json? Also, what version of knife-container and chef-init are you using?
yes, I am wondering if first-boot.json should have a 'service' rather than 'container_service'. But documentation page says 'container_service' so I've left it like this:
{ "run_list": [ "recipe[apt]", "recipe[apache2]" ], "container_service": { "apache2": { "command": "/usr/sbin/apache2 -k start" } } }
knife-container-docker-init command is :
Aha! I found the bug - thank you for pointing this out. The issue is that chef-init
is looking for new_resource.service_name when it should be looking for new_resource.name. This was an oversight on my part. That will be fixed in the next release of chef-init. For now the answer is to make sure that your node attribute value node['container_service']
uses the service_name rather than name.
{
"container_service": {
"httpd": {
"command": "<command>"
}
}
}
Also, please be aware that /usr/sbin/apache2 -k is not the correct runit command for httpd running on centos. Please refer to http://smarden.org/runit/runscripts.html#apache2.
Sorry, I don't understand what you mean about 'servicename' vs 'name' in first-boot.json. So what should the content be for my case?
Also, that 'runit' is new to me.... so what should be the command to start it on centos? thanks.
{
"container_service": {
"httpd": {
"command": "/usr/sbin/httpd -DFOREGROUND"
}
}
}
That works. Thanks. Final question : how can I get get chef-container to work in a RHEL 6 base image? Is there any procedure you can give me for that, as there is no downloadable RHEL + chef-container image?
You can see how I build our base images here: https://github.com/opscode/chef-container. You should be able to do something similar for any base image.
Perfect, will take a look . Thanks again.
Hi,
I'm running the sample explained in the blog "https://www.getchef.com/blog/2014/07/15/release-chef-container-0-2-0-beta/" , with chef/centos-6 base image.
While doing "# knife container docker build chef/tnpfa-centos" , it goes fine for most of it but gives this error towards the end :
-------------------- error fragment ----------------- [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/CHANGELOG.md in the cache. [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/.gitignore in the cache. [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/Gemfile in the cache. [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/CONTRIBUTING in the cache. [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/README.md in the cache. [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/.travis.yml in the cache. [2014-10-08T23:55:27+01:00] INFO: Storing updated cookbooks/pacman/LICENSE in the cache. [2014-10-08T23:55:28+01:00] INFO: Provider for service[apache2] has been replaced with Chef::Provider::ContainerService::Runit [2014-10-08T23:55:28+01:00] INFO: Processing execute[apt-get-update] action run (apt::default line 45) [2014-10-08T23:55:28+01:00] INFO: Processing execute[apt-get update] action nothing (apt::default line 53) [2014-10-08T23:55:28+01:00] INFO: Processing execute[apt-get autoremove] action nothing (apt::default line 61) [2014-10-08T23:55:28+01:00] INFO: Processing execute[apt-get autoclean] action nothing (apt::default line 68) [2014-10-08T23:55:28+01:00] INFO: Processing package[update-notifier-common] action install (apt::default line 75) [2014-10-08T23:55:28+01:00] INFO: Processing execute[apt-get-update-periodic] action run (apt::default line 80) [2014-10-08T23:55:28+01:00] INFO: Processing directory[/var/cache/local] action create (apt::default line 91) [2014-10-08T23:55:28+01:00] INFO: Processing directory[/var/cache/local/preseeding] action create (apt::default line 91) [2014-10-08T23:55:28+01:00] INFO: Processing package[apache2] action install (apache2::default line 20) [2014-10-08T23:55:43+01:00] INFO: package[apache2] installing httpd-2.2.15-31.el6.centos from updates repository [2014-10-08T23:56:03+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-08T23:56:04+01:00] INFO: Running queued delayed notifications before re-raising exception [2014-10-08T23:56:04+01:00] ERROR: Running exception handlers [2014-10-08T23:56:04+01:00] ERROR: Exception handlers complete [2014-10-08T23:56:04+01:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out [2014-10-08T23:56:04+01:00] ERROR: service[apache2](apache2::default line 24) had an error: NoMethodError: undefined method `[]' for nil:NilClass [2014-10-08T23:56:04+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) [2014-10-08T23:56:04+01:00] INFO: Deleting client key... 2014/10/08 17:56:18 The command [/bin/sh -c chef-init --bootstrap] returned a non-zero code: 1 WARNING: Deleted node chef-tnpfa-centos-build WARNING: Deleted client chef-tnpfa-centos-build -----------------------------end of error fragment----------------
I'd appreciate if you can point on why this isn't working. Its the standard apache2 cookbook I used.