Puppet – Restart a service after a file has changed

After we have used Puppet to update a service config file, we would like to restart the service so as to apply the new changes to the service.

Say for example, we want to keep the SSH service alive and whenever the /etc/ssh/sshd_config is synchronized from the Puppet server, restart the SSH service. This can be done as follow.

class system::ssh-service {
  # Install the required packages
  package { "openssh-server": ensure => installed }
  package { "openssh-client": ensure => installed }

  # Synchronize the sshd_config
  file { "/etc/ssh/sshd_config":
    mode    => 600,
    owner   => "root",
    group   => "root",
    require => Package["openssh-server"],
    notify  => Service["sshd"], # Restart ssh server if being updated
  }

  # Ensure the ssh server is running
  service { "sshd":
    ensure  => "running",
    enable  => "true",
    require => Package["openssh-server"],
  }
}

 

So whenever there is new update of sshd_config, the SSH service will be restarted.

Done =)

Reference: Puppet CookBook – Restart a service when a file changes

One thought on “Puppet – Restart a service after a file has changed”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.