Puppet can manage services on nearly all operating systems.This page offers operating system-specific advice and best practices for working with service.
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.
service { 'apache2':
ensure => running,
enable => true,
} Defective init script
On platforms that use SysV-style init scripts, Puppet assumes the script will have working start, stop, and status commands.
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 Hat network — 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
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
startorbinaryto specify a start command. The difference is thatbinaryalso gives you default behavior forstopandstatus. - 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
stopattribute 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
startcommand is just a script and a different process implements the service itself, use eitherstatus(a command that exits 0 if the service is running and nonzero otherwise) orpattern(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
restartattribute.
Using service on macOS
macOS handles services much like most *nix-based systems. The main difference is that enable and ensure are much more closely linked — running services are always enabled, and stopped ones are always disabled.
For best results, either leave enable blank or make sure it’s set to true whenever ensure => running.
/System/Library/LaunchDaemons/System/Library/LaunchAgents/Library/LaunchDaemons/Library/LaunchAgents
You can also specify start and stop commands to assemble your own services, much like on *nix systems.
Using service on Windows
On Windows, Puppet can start, stop, enable, disable, list, query, and configure services. It expects that all services will run with the built-in Service Control Manager (SCM) system. It does not support configuring service dependencies, the account to run as, or desktop interaction.
service resources for Windows, remember the following:Use the short service name (such as
wuauserv) in Puppet, not the display name (such asAutomatic Updates).Set
enable => trueto assign a service the Automatic startup type.Set
enable => manualto assign the Manual startup type.
service { 'mysql':
ensure => 'running',
enable => true,
}