Ask Your Question

How does the "ensure" attribute from the "service" resource test if a service is running?

asked 2016-06-09 16:35:10 -0600

tinatinatina gravatar image

Just to give a bit of context.

I'm working on a script to provision Mercurial.

There is an init script with "start" and "stop" capabilities.

I've written the following block to make sure the service is running.

  service { 'hg_serve':
     ensure => running,
     enable => true,

I'm running into an issue where this service tries to start itself every time the above resource runs. But of course after the initial provisioning, the port is already in use, so all subsequent provisioning fails because it tries to start a mercurial server on the same port.

Isn't ensure supposed to just check its status, instead of starting it?

I think the service provider is failing to recognize the status of this service and that's why it just tries to start it "to get the job done".

I've been looking through the puppet source code but can't find where the checks for "ensure" is located.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-06-09 21:32:23 -0600

virtblackbelt gravatar image

Have you tried, by hand, to see whether the service thinks it is running (as opposed to just the appropriate processes running). For example, RHEL "service hgserve status" or "systemctl status hgserve"? I've run across a couple of misbehaving applications that don't properly start and report status, so every time Puppet checked status it said it wasn't running and tried to start it.

edit flag offensive delete link more


look into hasstatus => false, and the pattern param. More info in my full answer.

DarylW gravatar imageDarylW ( 2016-06-09 21:54:23 -0600 )edit

Dary, where is the full answer? it seems I met with same issue, I am using a command such as " ps -ef|grep daemonname" as the status check. and I am sure it will return 0, but it seems the service status check does not use the return value 0/1 to decide whether to start/stop/restart service.

jamwu2 gravatar imagejamwu2 ( 2018-05-09 06:20:47 -0600 )edit

answered 2016-06-09 21:57:41 -0600

DarylW gravatar image

If your init script doesn't have a 'status' option, you have ways to tell the puppet service resource 'hasstatus => false, and you can give it further information about how to figure out status. run 'puppet describe service' to see info about param options.

Specifically, this part of the output...

Puppet 2.7 and newer expect init scripts to have a working status command.
If this isn't the case for any of your services' init scripts, you will
need to set `hasstatus` to false and possibly specify a custom status
command in the `status` attribute. As a last resort, Puppet will attempt to
search the process table by calling whatever command is listed in the `ps`
fact. The default search pattern is the name of the service, but you can
specify it with the `pattern` attribute.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-09 16:35:10 -0600

Seen: 258 times

Last updated: Jun 09 '16