Force custom service provider to never be default

6 views
Skip to first unread message

Daniel Urist

unread,
Jun 6, 2017, 5:22:48 PM6/6/17
to puppet-users
I've written a simple custom service provider for monit that inherits from the debian provider. Since this is running on debian systems, I want to use the debian "enable" to enable/disable running at boot, but I want monit to manage the running service rather than puppet. 

Puppet::Type.type(:service).provide :monitdummy, :parent => :debian do
  desc <<-'EOT'
Dummy provider for monit; always reports status as "running" so puppet
doesn't manage the running state
  EOT
  
  confine :exists => "/usr/bin/monit"
    
  def startcmd
    [ "/bin/true" ]
  end
  def stopcmd
    [ "/bin/true" ]
  end
  def restartcmd
    [ "/bin/true" ]
  end  
  def statuscmd
    [ "/bin/true" ]
  end
end

It works for what I need. My problem is that this has now become the default provider on my system, according to facter:

# facter -p | grep service
service_provider => monitdummy

I've tried adding a call to "defaultfor" like this:

defaultfor :operatingsystem => 'none'
 
...but that doesn't have any effect, I guess because it's inheriting the defaultfor from the debian provider and there can be multiple? 

Looking at the code in https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb, there is the function "self.specificity" that picks the provider with the most ancestors, so I guess that's why my provider gets picked over debian.

I realize I could set debian as the default provider with "Service { provider => 'debian' }" in a high-level manifest, but that seems less than ideal since it short-circuits puppet's provider selection-- what I'd really like would be for a way to ensure that my custom provider is never the default.

Is there any way to do this?


Reply all
Reply to author
Forward
0 new messages