I was trying to kill spurious resource updating, and noticed that on ubuntu the nginx cookbook will re-enable the nginx resource on every run.
So far as I can tell, everything comes down to this line in Chef::Provider::Service::Debian#action_enable: https://github.com/opscode/chef/blob/master/lib/chef/provider/service/debian.rb#L116
The trick is that it not only verifies that the service is enabled (duh) but that the desired priority matches the current priority.
But looking at the service resource’s initializer: https://github.com/opscode/chef/blob/master/lib/chef/resource/service.rb#L44
You can see that the default
@new_resource.priority will be nil, whereas the default
@current_resource.priority for a sane enabled service will be something like:
0 => :stop,
1 => :stop,
2 => :start,
3 => :start,
4 => :start,
5 => :start,
6 => :stop
What’s the reasonable thing to do? Have init-style services explicitly define their priorities (not-newb-friendly)? Only check if the service is enabled (that is, enabled in any of run levels 2-5)? Set a non-nil default priority for init services? Something else?