summaryrefslogtreecommitdiff
path: root/openwrt/rhctl/files/rhctl-healthcheck
blob: d2f8da476bd13131a1f8d45bd74e3c56d0a94b82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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