Start Service Not Working

Hey All,

I’m having some issues getting a service to start and wanted to make sure I’m not doing something stupid.

I’m installing varnish and then using the service module to start and enable varnish.

  • name: start and enable service
    service: name=varnish state=started

All seems fine when I do a fresh provision of a box. The issue I’m seeing is that if I log into the box and stop the service and re-provision, I get a green light at the task and the service never gets started.

Am I doing something wrong?

Thanks!

James

Hey All,

I’m having some issues getting a service to start and wanted to make sure I’m not doing something stupid.

Ummm, That’s kind of hard to say without knowing what you are doing… This is not an RTFM response, so please read it and see if this helps, or if you can at least answer the questions so that we can (possibly) help you.

I’m installing varnish and then using the service module to start and enable varnish.

  • name: start and enable service
    service: name=varnish state=started

All seems fine when I do a fresh provision of a box. The issue I’m seeing is that if I log into the box and stop the service and re-provision, I get a green light at the task and the service never gets started.

Which version of Ansible are you using? What OS are you running the task against? How are you stopping the service? What do you mean by re-provision?

In particular I’m wondering if you are killing the varnish service so that it is no longer running and then the script is checking to see if the system thinks that varnish is running (there is still a lock file or something sitting around). If that is the case then Ansible doesn’t know that it is not running, so it doesn’t start it.

By the way, that just starts varnish, to enable it at boot time you would use

  • name: Start and Enable Varnish
    service: name=varnish state=started enabled=yes

I hope that this helps,

Adam

Hey Adam,

Thanks for the reply!

I’m running Ansible 1.5.3 and am running the task again Ubuntu 12.04. When I say re-provision, I mean re-running the task.

The way I’m killing the service is logging into the box and running “service varnish stop”. If I subsequently run the command “service varnish status” it shows it as stopped.

Thanks for the tip on using the enabled flag – I’m using it but left it off the example i pasted in.

  • James

So I played around a bit more with this and it seems to be happening for all of the services in my playbook. Is it possible this is a bug? All works fine the first time through, but once Ansible starts a service, it never looks at it again unless you call Restart or Stop. It seems it would be good to have it make sure the service is actually running.

Can anyone verify they’re seeing the same thing?

I've seen this behaviour quite often when a service scripts 'status'
command isn't written properly.

'service thingy status' is supposed to return true or false (and
optionally print some sort of readable message),
and _loads_ tend to return the wrong exit code.

You can work around it by falling back to grepping ps - see the
'pattern' clause on service: .