howto/cumin: trick for tunnel: confirm that port 8080 is used by puppetdb authored by lelutin's avatar lelutin
port 8080 is fairly popular so many things can be binding to that port.
Today I had a container running that was bound to it and puppetdb
queries would not work (quite unsurprisingly). The cumin function in the
trick for automatically setting up the tunnel now checks whether the
port will respond to a simple puppetdb query.

`echo -e` was a typo. really I wanted that to be `-n` so that the dots
showing the waiting would be on the same line. The new `echo "x"` is
there to indicate the error in the waiting line but also to move the
error message to a new line, where it's easier to read
......@@ -105,7 +105,7 @@ Somewhere in your `~/.bashrc`, add the following:
# needed.
function cumin () {
if ! nc -z localhost 8080 2>/dev/null; then
echo -e "NOTE: starting tunnel with puppetdb, watch out for your token being sollicited" >&2
echo -n "NOTE: starting tunnel with puppetdb, watch out for your token being sollicited: " >&2
systemctl --user start puppetdb-tunnel.service
for i in {0..60}; do
if nc -z localhost 8080 2>/dev/null; then
......@@ -114,6 +114,7 @@ Somewhere in your `~/.bashrc`, add the following:
break
else
if [[ $i -eq 60 ]]; then
echo "x" >&2
echo "error: tunnel not started correctly, bailing out" >&2
return 1
fi
......@@ -121,6 +122,9 @@ Somewhere in your `~/.bashrc`, add the following:
sleep 1
fi
done
elif ! curl -s http://localhost:8080/pdb/meta/v1/version | jq .version >/dev/null 2>&1; then
echo "ERR: localhost:8080 is listening but it does not seem to be used by puppetdb." >&2
return 1
fi
# Now hand off the arguments to actually run cumin
/usr/bin/cumin --config=~/.config/cumin/config.yaml "$@"
......
......