Using service on *nix systems

If your *nix operating system has a good system for managing services, and all the services you care about have working init scripts or service configs, you can write small service resources with just the ensure and enable attributes.

For example:

service { 'apache2':
  ensure => running,
  enable => true,
}
Some *nix operating systems don't support the enable attribute.

Defective init script

On platforms that use SysV-style init scripts, Puppet assumes the script has working start, stop, and status commands. See descriptions below.

If the status command is missing, set hasstatus => false for that service. This makes Puppet search the process table for the service’s name to check whether it’s running.

In some rare cases — such as virtual services like the Red Hatnetwork — a service won’t have a matching entry in the process table. If a service acts like this and is also missing a status command, set hasstatus => false and also specify either status or pattern attribute.

No init script or service config

If some of your services lack init scripts, Puppet can compensate, as in the following example:

service { "apache2":
  ensure  => running,
  start   => "/usr/sbin/apachectl start",
  stop    => "/usr/sbin/apachectl stop",
  pattern => "/usr/sbin/httpd",
}
In addition to specifing ensure, specify also how to start the service, how to stop it, how to check whether it’s running, and optionally how to restart it.

Start

Use either start or binary to specify a start command. The difference is that binary also gives you default behavior for stop and status.

Stop

If you specified binary, Puppet defaults to finding that same executable in the process table and killing it. To stop the service some other way, use the stop attribute to specify the appropriate command.

Status

If you specified binary, Puppet checks for that executable in the process table. If it doesn’t find it, it reports that the service isn’t running.
If there’s a better way to check the service’s status, or if the start command is just a script and a different process implements the service itself, use either status (a command that exits 0 if the service is running and nonzero otherwise) or pattern (a pattern to search the process table for).

Restart

If a service needs to be reloaded, Puppet defaults to stopping it and starting it again. If you have a safer command for restarting a service, you can optionally specify it in the restart attribute.