A collection of task oriented solutions in Puppet

 

Ensure service starts on boot

Challenge

You want to ensure a service starts on boot.

Solution

class enable_service {

  service { 'puppet':
    enable => true,
  }

}
# let's show this snippet in action
# puppet won't start on boot
$ chkconfig --list puppet
puppet          0:off 1:off 2:off 3:off 4:off 5:off 6:off

# "enable" the service
$ sudo puppet apply -e 'service { "puppet": enable => true, } '
notice: /Stage[main]//Service[puppet]/enable: enable changed 'false' to 'true'
notice: Finished catalog run in 0.25 seconds

# double check it (on Redhat derived systems)
$ chkconfig --list puppet
puppet          0:off 1:off 2:on  3:on  4:on  5:on  6:off

Explanation

Sometimes you want to ensure that a service starts when the host boots. In puppet you accomplish this by setting the enable property on a service resource.

If this property is set without the related Ensure service is running also being present puppet will not restart the service if it is terminated.

See also