summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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