diff options
Diffstat (limited to 'openwrt/rhctl/files/rhctl-healthcheck')
-rwxr-xr-x | openwrt/rhctl/files/rhctl-healthcheck | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/openwrt/rhctl/files/rhctl-healthcheck b/openwrt/rhctl/files/rhctl-healthcheck new file mode 100755 index 0000000..d2f8da4 --- /dev/null +++ b/openwrt/rhctl/files/rhctl-healthcheck @@ -0,0 +1,27 @@ +#!/bin/sh + +URL="http://localhost:4080/api/state" +ATTEMPTS=2 + +fail_cnt=0 +for i in $(seq 1 $ATTEMPTS); do + if [ $i -gt 1 ]; then + sleep 3 + fi + + curl -s -f --connect-timeout 5 -m 15 "$URL" > /dev/null + RET=$? + if [ "$RET" -ne 0 ]; then + fail_cnt=$((fail_cnt + 1)) + echo "attempt $i failed with code $RET" | logger -t "rhctl-healthcheck" + else + echo "attempt $i succeeded" | logger -t "rhctl-healthcheck" + fi +done + +if [ "$fail_cnt" -gt 1 ]; then + echo "rhctl health check failed $fail_cnt times: restarting daemon" | logger -t "rhctl-healthcheck" + /etc/init.d/rhctl restart +else + echo "rhctl health check failed $fail_cnt times: nothing to be done" | logger -t "rhctl-healthcheck" +fi |