How can I ensure that a service is started/stopped based on if it is needed or not ?

57 views
Skip to first unread message

Glenn Poston

unread,
Sep 8, 2012, 11:57:50 PM9/8/12
to puppet...@googlegroups.com
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.

Sébastien Lavoie

unread,
Sep 9, 2012, 12:38:44 AM9/9/12
to puppet...@googlegroups.com
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

Jakov Sosic

unread,
Sep 9, 2012, 7:02:48 AM9/9/12
to puppet...@googlegroups.com
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

R.I.Pienaar

unread,
Sep 9, 2012, 7:34:03 AM9/9/12
to puppet...@googlegroups.com


----- Original Message -----
> From: "Sébastien Lavoie" <seba...@lavoie.sl>
> To: puppet...@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.

Sébastien Lavoie

unread,
Sep 9, 2012, 10:38:53 AM9/9/12
to puppet...@googlegroups.com
@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.
Reply all
Reply to author
Forward
0 new messages