ffs-watchdog 666 Bytes
Newer Older
1 2 3 4 5 6 7
#!/bin/sh
ME=$(basename $0)
if [ $(ps | grep -c "$ME") -gt 4 ]; then
  logger -s -t $ME "started twice"
  exit 1
fi

8
FFS=/tmp/.gw.ffs
9 10
if [ "$(uci get gluon-setup-mode.@setup_mode[0].enabled)" = "0" ] &&
   [ "$(uci get system.@system[0].enable_watchdog)" != "0" ]; then
11 12 13 14 15 16 17 18 19 20
  NOW=$(date +%s)
  if [ -n "$(batctl gwl | grep '=>')" ]; then
    echo $NOW >$FFS
    logger -t $ME "node is online"
  else
    if [ -f $FFS ]; then
      OFF=$(cat $FFS)
      DELTA=$((NOW - OFF))
      logger -t $ME "offline for ${DELTA} sec."

FFS-Roland's avatar
FFS-Roland committed
21
      if [ $DELTA -gt 3500 ]; then
22 23 24 25 26 27
        reboot
      fi
    else
      echo $NOW >$FFS
    fi
  fi
28 29 30
else
  rm $FFS
  logger -t $ME "disabled"
31
fi