----- Original Message ----- > From: "Sébastien Lavoie" <sebast...@lavoie.sl> > To: puppet-users@googlegroups.com > Sent: Friday, September 7, 2012 11:32:55 PM > Subject: [Puppet Users] How can I ensure that a service is started/stopped > based on if it is needed or not ? > > I have a several services that I use only for some sites and I would > like to make sure it is started when a site that uses is activated > and stopped when it is not needed anymore. > > > Examples: memcache, elasticsearch, rabbitmq, etc. > > > I can easily make a service virtual and realize it before making a > reference to it like this: > > > class webserver { > @service {"memcache": > ensure => running, > } > } > > > class sites { > Realize['memcache'] > site {"example.com": > require => Service['memcache'] > } > } > > > But this will not stop the service if it is never realized.
dont know if this helps but lets say you have a common class you install on all nodes: class common { include memcache } class memcache { service{"memcache": ensure => stopped, enable => false} } at this point if you include common on all machines memcache will be stopped and disabled everywhere now you make a class specifically to include on nodes that needs it running. class memcache::enable inherits memcache { Service["memcache"] { ensure => running, enable => true } } if you include this class on a node it will be enabled, soon as you remove the class it will be disabled again Generally though this is a bad idea because you also have to consider configs, packages and all this stuff it might make sense in your case but I think the correct thing to do is just not to install stuff on machines that you dont need. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.