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

Advertisements

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s