#!/bin/sh
# E3 (readiness analysis): puppetserver is READY when it answers the status
# page on 8140 with "running" -- not when the JVM is running.
#
# Until then, depending on the node, 12 s to over a minute pass (JVM startup,
# JRuby pool, on the first start the CA). "up" is true and useless during this
# time: exactly then the first agent run, certificate issuance and every
# acceptance test depend on it (measured: puppet-1.tick1 did not have a single
# service with readiness notification).
#
# What is checked is the RESPONSE, not curl's exit code. /status/v1/simple
# needs no authentication (auth.conf of the upstream packages) and says
# "running" as soon as all services have started; during startup the port is
# closed or the response is something else.
#
# -k: the request goes to 127.0.0.1, the server certificate carries the node
# name -- a name check would be wrong here, and on the very first start there
# is no CA yet to check against. Only our own loopback is queried.
#
# Port 8140 is the upstream default (webserver.conf ssl-port). Whoever changes
# it must change this check along with it.
r=$(curl -sk -m 5 https://127.0.0.1:8140/status/v1/simple 2>/dev/null) || exit 1
[ "$r" = running ]
