summaryrefslogtreecommitdiff
path: root/openwrt/rhctl/files
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2018-11-07 13:23:38 (GMT)
committerChristian Pointner <equinox@helsinki.at>2018-11-07 13:23:38 (GMT)
commitd97d6b83ede22a39a17c18a6c1037ece2610f01c (patch)
tree8fc75eaaa673c175faba364227c18cb8ade25168 /openwrt/rhctl/files
parentb141c2d018365a717aa16982b772fe800062b40f (diff)
added rhctl healthcheck
Diffstat (limited to 'openwrt/rhctl/files')
-rwxr-xr-xopenwrt/rhctl/files/rhctl-healthcheck27
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