Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 0.7.14
-
Fix Version/s: 0.9.10
-
Component/s: Chef Client, Chef Solo
-
Labels:None
-
Environment:
centos
-
Triage Status:Triaged
Description
I have a simple task: start a service with a custom config file. I have very a simple recipe:
service "syslog-ng" do
supports :start => true, :stop => true, :restart => true, :status => true
action [ :enable, :start ]
end
template "/etc/syslog-ng/syslog-ng.conf" do
source "syslog-ng.conf.erb"
notifies :restart, resources(:service => "syslog-ng")
end
But chef will start the service before putting in the config file. So I can make Chef fail simply by doing this:
$ service collectd stop
$ echo xx > /etc/collectd.conf
$ chef-solo
INFO: Starting Chef Solo Run
ERROR: service[collectd] (/home/chef/cookbooks/collectd/recipes/default.rb line 4) had an error:
/sbin/service collectd start returned 1, expected 0
---- Begin output of /sbin/service collectd start ----
STDOUT: Starting collectd: [FAILED]STDERR: Parse error in file `/etc/collectd.conf', line 2 near `<newline>': syntax error, unexpected EOL
yyparse returned error #1
Error: Reading the config file failed!
Read the syslog for details.
---- End output of /sbin/service collectd start ----
Ideally, the order of the entries in the recipe would be reversed, since the collectd service clearly depends on the collectd.conf config file. But if I try switching the stanzas, it gives me an error:
/usr/lib/ruby/gems/1.8/gems/chef-0.7.14/lib/chef/resource_collection.rb:107:in `lookup': Cannot find a resource matching service[collectd] (did you define it first?) (ArgumentError)
Looking at the opscode-cookbook examples, I can see 2 camps:
- munin and postgres don't attempt to start the service at all, but rely on the change in config files to restart it. (real bad if you already have the right config, or if chef crashes after the config file is installed)
- nginx starts the service, but doesn't attempt to restart the service when the config file is changed.
Neither one is "correct" as far as I'm concerned. Chef should be happy reversing the stanzas, because that's the correct dependency order.
oops, pasted wrong recipe vs error text. But you get what I mean.