Ask Your Question
1

Restarting a service from another module

asked 2017-03-24 13:21:07 -0500

CBR gravatar image

updated 2017-03-24 13:22:24 -0500

Hello,

I have two modules A,B. I wanted to restart a service defined in module A when a config file is updated by module B. How would I do that?

This is how my existing modules have

module A: has sshd service as resource defined. module B: configures sshd_config file but I need service of module A to do the restart

This is what I have in init.pp of module B.

    class B () {  
       include A  
       contain B::a  
       contain B::b  

    Class['B::a'] ~> Class['A'] -> Class['B::b']  

}

My question is instead of doing ~>Class['A'] in init.pp, can I have notify => Service['A'] in one of the module B classes within the resource definition?

If yes, how do I do that ?
What is the preferred way of doing this ?

edit retag flag offensive close merge delete

Comments

1

That sounds like bad design. Why's your sshd_config file managed by another module than the sshd module itself? https://forge.puppet.com/tags/sshdhttps://docs.puppet.com/puppet/latest/lang_resources_advanced.html#amending-attributes-with-a-resource-reference Service['sshd']{subscribe+>File['conf']}

Kai Burghardt gravatar imageKai Burghardt ( 2017-03-25 12:20:34 -0500 )edit

Because file package resource is a common way of delivering a resource like sshd

puser gravatar imagepuser ( 2017-03-27 06:16:13 -0500 )edit

if you threw sshd and all the configs in one module then if you ever needed to deliver sshd alone with some other config you would need to refactor.

puser gravatar imagepuser ( 2017-03-27 06:33:12 -0500 )edit

Good modules let you enable disable what they manage. Also they let you drop in what template to use for sshd_config generation.

Kai Burghardt gravatar imageKai Burghardt ( 2017-03-27 11:07:07 -0500 )edit

So are you saying that your sshd module would have every sshd config and you would allow the consumer to enable each config individually? It makes more sense to deliver the service and allow the user to consume it like above.

puser gravatar imagepuser ( 2017-03-27 12:20:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-03-27 06:18:11 -0500

puser gravatar image

updated 2017-03-27 06:19:54 -0500

if the classes you are including in your module contain the service and the config then you can do a notify. Puppet will automatically order the processing of the resources based on notifys and includes.

Module A -> has some sshd configs Module B -> provides sshd service

If Module C includes both A & B (or some kind of variation) then you can do a notify.

sshd_config { 'some_config':
  #Do something
  notify => Service['sshd'],
}

Should do the trick.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-24 13:21:07 -0500

Seen: 105 times

Last updated: Mar 27