summaryrefslogtreecommitdiff
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
parentb141c2d018365a717aa16982b772fe800062b40f (diff)
added rhctl healthcheck
-rw-r--r--openwrt/rhctl/Makefile3
-rwxr-xr-xopenwrt/rhctl/files/rhctl-healthcheck27
2 files changed, 29 insertions, 1 deletions
diff --git a/openwrt/rhctl/Makefile b/openwrt/rhctl/Makefile
index b126c32..b07a2cf 100644
--- a/openwrt/rhctl/Makefile
+++ b/openwrt/rhctl/Makefile
@@ -47,7 +47,7 @@ endef
define Build/Compile
export GOROOT=/opt/go
- $(MAKE) -C $(PKG_BUILD_DIR)/ build-alix
+ $(MAKE) -C $(PKG_BUILD_DIR)/ build-alix
endef
define Package/rhctl/install
@@ -55,6 +55,7 @@ define Package/rhctl/install
$(INSTALL_DATA) ./files/config.toml $(1)/etc/rhctl/
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bin/linux_386/rhctl $(1)/usr/bin/
+ $(INSTALL_BIN) ./files/rhctl-healthcheck $(1)/usr/bin/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/rhctl.init $(1)/etc/init.d/rhctl
$(INSTALL_DIR) $(1)/usr/lib/check_mk_agent/plugins
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