Sébastien Lavoie
2012-Sep-07 22:32 UTC
[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. Any ideas ? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/UrHwRHoRbTIJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Glenn Poston
2012-Sep-09 03:57 UTC
[Puppet Users] How can I ensure that a service is started/stopped based on if it is needed or not ?
You could create a fact that returns true or false, then use that fact in your puppet code to determine whether to start the service. I''d need more details to really say that''s the best solution though. Other options would be to use heira or to use a parameterized class and set those parameters in your ENC/mode definition. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/yoOmxcLYlVAJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Sébastien Lavoie
2012-Sep-09 04:38 UTC
[Puppet Users] Re: How can I ensure that a service is started/stopped based on if it is needed or not ?
I am not experienced in creating facts, could you give me a better idea ? I fail to see how a fact could detect if a service is required. Thanks On Saturday, 8 September 2012 23:57:50 UTC-4, Glenn Poston wrote:> > You could create a fact that returns true or false, then use that fact in > your puppet code to determine whether to start the service. I''d need more > details to really say that''s the best solution though. Other options would > be to use heira or to use a parameterized class and set those parameters in > your ENC/mode definition.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/9Tmhu-YGFaoJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Jakov Sosic
2012-Sep-09 11:02 UTC
Re: [Puppet Users] Re: How can I ensure that a service is started/stopped based on if it is needed or not ?
On 09/09/2012 06:38 AM, Sébastien Lavoie wrote:> I am not experienced in creating facts, could you give me a better idea > ? I fail to see how a fact could detect if a service is required.And how do you determine if it''s required? By hostname, or? -- Jakov Sosic www.srce.unizg.hr -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
R.I.Pienaar
2012-Sep-09 11:34 UTC
Re: [Puppet Users] How can I ensure that a service is started/stopped based on if it is needed or not ?
----- Original Message -----> From: "Sébastien Lavoie" <sebastien@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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Sébastien Lavoie
2012-Sep-09 14:38 UTC
Re: [Puppet Users] How can I ensure that a service is started/stopped based on if it is needed or not ?
@Jakov I am currently running Puppet on a single host, it is only to manage site configurations, so this is not a problem @R.I. Thanks, worked like a charm. Bonus points for very simple solution. On Sunday, September 9, 2012 7:34:10 AM UTC-4, R.I. Pienaar wrote:> > > > ----- Original Message ----- > > From: "Sébastien Lavoie" <seba...@lavoie.sl <javascript:>> > > To: puppet...@googlegroups.com <javascript:> > > 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 view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/6PzT8Tk2cMwJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.