A collection of task oriented solutions in Puppet

 

Ensure service is running

Challenge

You want to ensure a service is running and have puppet restart it when needed.

Solution

class running_service {

  service { 'cron':
    ensure => 'running',
  }

}

Explanation

There are services that should always be running and, if they are ever stopped, should be restarted. By setting the ensure service property to running (or true) puppet will check for the presence of the service on each run and restart it when it's absent.

This property is often used with service enable to ensure a service is both running and starts on system boot.

See also