Puppet: restart service on file changes

If you want a service to restart on some kind of action, you can use the notify parameter in Puppet.

This example is with ssh, and it will notify the sshd-service, and restart it, if changes has been made to the sshd_config-file in the latest pull from the agent.

First of all, i make sure that the service is always on and running (the required-parameter, means that the package needs to be installed for this to be used - defined further up in the file):

service { "sshd" :
  ensure => "running",
  enable => "true",
  require => Package["openssh-server"],

Then i have this file block, which will pull down the sshd_config-file from my puppet master file server, and if any changes has been done (or if this file-block has been used in general), it will notify the sshd-service, and restart the sshd-service ($ notify => Service["sshd"]):

file { "/etc/ssh/sshd_config" :
  notify => Service["sshd"],
  mode   => 700,
  owner  => root,
  group  => root,
  source => "puppet:///modules/solido-ssh/sshd_config",

From now on i will write some posts just for reference, like this one, for example for software like Puppet.