Need help fixing CHEF-2345 unable to override supports :status for redhat services


#1

Hoping you guys can help me as I couldn’t quite come up with a fix for
this bug. I think the desired feature was that :status should default
to true for Redhat rather than false with other providers, but because
lib/chef/provider/service/redhat.rb does:

@new_resource.supports[:status] = true

The effect is that :status always = true and you can’t set it to false
such as if you have a misbehaving 3rd party init script you can’t fix.
This is lame. Problem is that the defaults come from the resource code
not the provider so I think that the way to fix this is in
lib/chef/resource/service.rb when the defaults are set:

@supports = { :restart => false, :reload => false, :status => false }

But to do this I need to inspect the provider to know if we’re on
redhat, something like:

if provider == ‘Chef::Provider::Service::Redhat’
@supports = { :restart => false, :reload => false, :status => true }
else
@supports = { :restart => false, :reload => false, :status => false }
end

But provider is nil at that point. Tried calling straight to
Chef::Platform.provider_for_resource(self) but that doesn’t work
either because the run_context isn’t set at that point.

Anyone got another angle or a way to make this work?

Thanks,

KC


#2

Ohai!

On Jun 7, 2012, at 5:26, KC Braunschweig kcbraunschweig@gmail.com wrote:

@new_resource.supports[:status] = true

The effect is that :status always = true and you can’t set it to false
such as if you have a misbehaving 3rd party init script you can’t fix.
This is lame.

Anyone got another angle or a way to make this work?

Have you tried using status_command parameter on the services with init scripts that don’t have status?

service “third-party” do
status_command "a command that checks if it’s running"
end

You would of course use whatever command is appropriate.


#3

Would an ||= work in that case? I’ve not dug into the providers in
quite some time.

On Thu, Jun 7, 2012 at 7:26 AM, KC Braunschweig
kcbraunschweig@gmail.com wrote:

Hoping you guys can help me as I couldn’t quite come up with a fix for
this bug. I think the desired feature was that :status should default
to true for Redhat rather than false with other providers, but because
lib/chef/provider/service/redhat.rb does:

@new_resource.supports[:status] = true

The effect is that :status always = true and you can’t set it to false
such as if you have a misbehaving 3rd party init script you can’t fix.
This is lame. Problem is that the defaults come from the resource code
not the provider so I think that the way to fix this is in
lib/chef/resource/service.rb when the defaults are set:

@supports = { :restart => false, :reload => false, :status => false }

But to do this I need to inspect the provider to know if we’re on
redhat, something like:

if provider == ‘Chef::Provider::Service::Redhat’
@supports = { :restart => false, :reload => false, :status => true }
else
@supports = { :restart => false, :reload => false, :status => false }
end

But provider is nil at that point. Tried calling straight to
Chef::Platform.provider_for_resource(self) but that doesn’t work
either because the run_context isn’t set at that point.

Anyone got another angle or a way to make this work?

Thanks,

KC