-# No need for verbose printing during repeating operations.
-set +x
-
-echo "Waiting for controller to come up..."
-COUNT=0
-while true; do
- RESP="$(curl --user admin:admin -sL -w "%{http_code} %{url_effective}\\n" http://localhost:8181/restconf/modules -o /dev/null || true)"
- echo "${RESP}"
- if [[ "${RESP}" == *"200"* ]]; then
- echo Controller is UP
- break
- elif (( "${COUNT}" > 600 )); then
- echo Timeout Controller DOWN
- echo "Dumping Karaf log..."
- cat "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
- echo "Listing all open ports on controller system"
- netstat -pnatu
- exit 1
- else
- COUNT=$(( ${COUNT} + 1 ))
- sleep 1
- if [[ $(($COUNT % 5)) == 0 ]]; then
- echo already waited ${COUNT} seconds...
- fi
- fi
-done
+function dump_log_and_exit {
+ echo "Dumping first 500K bytes of karaf log..."
+ head --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
+ echo "Dumping last 500K bytes of karaf log..."
+ tail --bytes=500K "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log"
+ cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log" .
+ cp "${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf_console.log" .
+ exit 1
+}