Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet wait for a service to be ready

I am using Puppet for machines provisioning. I have a service running in Tomcat 6 app server and another manifest being dependant on that service (sending some REST requests as part of the installation). The problem is, the service is not available right after tomcat being started using:

service {"tomcat6":
  ensure  => running, enable => true, hasstatus => true, hasrestart => true;
}

So I need some require condition for another manifest that would ensure that the service is really running (e.g. checking some URL to be available). And in case it's not ready yet wait some time and try it again with some limit on the amount of retries.

Is there some idiomatic Puppet solution, or some another, that would achieve this?

Note - sleep is not a solution.

like image 437
iNecas Avatar asked Nov 23 '11 15:11

iNecas


1 Answers

Thanks to lzap and people in Puppet irc channel here is a solution:

exec {"wait for tomcat":
  require => Service["tomcat6"],
  command => "/usr/bin/wget --spider --tries 10 --retry-connrefused --no-check-certificate https://localhost:8443/service/",
}

When using require => Exec["wait for tomcat"] in dependant manifest, it won't run until the service is really ready.

like image 81
iNecas Avatar answered Nov 02 '22 11:11

iNecas