Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 10.14.0
-
Fix Version/s: 10.14.0
-
Component/s: Chef Client
-
Labels:None
-
Environment:
Centos 5.5, 64bit using chef 10.14.0.rc.0 installed via ruby gems.
Description
In previous versions of chef, attempting to disable a service that does not exists on a server did not throw any errors. With 10.14.0.rc.0, I get the following Fatal error when chef-client attempts to make sure syslog is stopped and disabled.
================================================================================
Error executing action `disable` on resource 'service[syslog]'
================================================================================
Chef::Exceptions::Service
-------------------------
service[syslog]: unable to locate the init.d script!
Resource Declaration:
---------------------
- In /srv/chef/cache/cookbooks/rsyslog/recipes/default.rb
23:
24: service "syslog" do
25: action [:disable, :stop]
26: end
27:
Compiled Resource:
------------------
- Declared in /srv/chef/cache/cookbooks/rsyslog/recipes/default.rb:24:in `from_file'
service("syslog") do
action [:disable, :stop]
supports {:restart=>false, :reload=>false, :status=>true}
retries 0
retry_delay 2
service_name "syslog"
pattern "syslog"
startup_type :automatic
cookbook_name "rsyslog"
recipe_name "default"
end
To me, the previous behavior of not throwing an error if the init script didn't exist makes sense, because this is a stop and disable action. If the init script doesn't exist, well... it's already disabled and Chef doesn't need to do anything and can continue.
It only makes sense to throw an error if there is an enable or start action and the init script doesn't exist. If this behavior remains, it will unnecessarily complicate my chef code.
Just to elaborate, what I'm doing here in my chef code is stopping and disabling the default syslog service and I have other code that installs rsyslog and enables and starts it.
I don't think it's so clear-cut.
There have been questions before, people wondering why Chef doesn't create an init script—and the general consensus was that the service resource should assume everything is set up correctly, including an init script.
Following that line of reasoning, if I ask Chef to stop a service and the init script is missing, Chef won't be able to stop it—and that's a fatal error if there ever was one.
The stop action cannot assume the recipe is also calling disable—maybe the recipe is stopping it to apply some changes and then start it again. If the service doesn't stop, all bets are off; subsequent actions may corrupt data and so on.
The disable action is different.
On most distros it doesn't depend on the init script at all, in which case I agree it can ignore the absence of the init script.
The bottom line is, the service shouldn't swallow exceptions.
I think that's already the case, so here's my vote for rejecting this ticket.
(Note that I'm not arguing the implementation is perfect—if a distro-specific init system doesn't need the init script to disable the service yet it fails, then the distro-specific provider should be fixed. I'm only arguing this shouldn't leak into the generic provider)