Ask Your Question
0

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

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

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
1

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

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
1

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

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

Comments

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

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

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

Stats

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

Seen: 64 times

Last updated: Jun 09 '16