On Wednesday, April 1, 2015 at 10:15:45 AM UTC-5, Guy Matz wrote:
>
> Hi!  I have a process that is controlled by daemontools on some servers, 
> and by init on other (i know, i know) and I need a way to have a Service 
> definition when daemontools is not in the run.  
>
> I've tried this:
>   unless defined(Class['daemontools']) {
>     notify { 'I Do not see daemontools': }
>     service { $dw_service:
>       ensure    => 'running'
>     }
>   }
>
> but that didn't work.  I've also tried Class['Daemontools'].
>


You are approaching the problem the wrong way.  It is *never* a good idea 
to base decisions about which classes and resources to declare on which 
have already been declared at some particular point during catalog 
building.  Doing so introduces an evaluation-order dependency, which will 
then hide in a dark corner, waiting for an opportunity to leap out and 
clamp its jaws on your backside.

Ideally, you wouldn't even have to worry about this.  If on all machines 
you are using Puppet's idea of the default Service provider, then just 
declare your service resource somewhere, without regard to whether it will 
be handled by daemontools or not.  All nodes that need the service get it 
from the same declaration.

If you are using daemontools to handle the service of interest on some 
machines where another provider (e.g. init) is the default, then you *still*, 
at some level, want all nodes that need it to obtain it via the same 
declaration.  In that case, you must already have a means to know based on 
node identity and/or facts whether your machines rely on daemontools.  Use 
that mechanism to control details of the service declaration, and any 
ancillary declarations.  A simple implemention of that might go thusly:
 
class myservice::service ($usedaemontools = 'false') {
  include 'myservice::software'  
  service { 'myservice':
    enable   => true,
    ensure   => running,
    provider => $usedaemontools ? {
      'true'   => 'daemontools',
      default  => undef
    },
    require  => Package['myservice']
  }
}

That same class would be declared for every node that needs service 
"myservice"; a class parameter (preferably obtaining its value via 
automatic data binding) determines whether the provider is overridden to 
"daemontools".

Your needs may be more complex, but the same general idea can be applied.  
It boils down to relying directly on data to determine what to declare, not 
on what has already been declared.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/076de90e-196a-4f1d-bf77-96ad60586d36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to