The puppet waits for the service to be ready

I use Puppet to prepare computers. I have a service running on the Tomcat 6 application server, and another manifest is dependent on this service (sending some REST requests as part of the installation). The problem is that the service is not available immediately after starting tomcat using:

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

So I need some kind of condition for another manifest that will ensure that the service really works (for example, checking which URL will be available). And if he is not ready yet, wait a while and try again with some restriction on the number of attempts.

Is there any idiomatic solution of the Puppeteer, or some other that will achieve this?

Note. Sleep is not a solution.

+6
source share
3 answers

Thanks to lzap and the people in the Puppet irc channel there 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 a dependent manifest, it will not work until the service is ready.

+17
source

Not a puppet, but a shell ...

 max=30; while ! wget --spider http://localhost:8080/APP > /dev/null 2>&1; do max=$(( max - 1 )); [ $max -lt 0 ] && break; sleep 1 done; [ $max -gt 0 ] 

This is an improved version.

It returns true when the application was found, false when max is reached.

+1
source

I know this is not a doll, but:

 max=30; e=1; while [ $e -ne 0 -a $max -gt 0 ]; do wget --spider http://localhost:8080/APP > /dev/null 2>&1 e=$?; max=$(( max - 1 )); sleep 1 done; [ $max -ne 0 ] 

You can put it on one line, just concatenate it with the help of a half-committee (except for the "do" statement).

0
source

Source: https://habr.com/ru/post/902214/


All Articles