#!/bin/sh
# Program
#          Program that will start and kill Supermicro thin-agent service

prog="Thin-Agent WatchDog"
TAS_BIN="/opt/supermicro/IPMITAS"
TAS_LOG="/opt/supermicro/tas_system_crush.log"
monitor=1


recover_tas() {
  $TAS_BIN -agent start-service
  RETVAl=$?
  return $RETVAL
}

stop() {
  watch=`ps -x | grep watchtas | grep -v grep | awk '{print $1}'`

  if [ $? -eq 0 ]; then
    for i in $watch
      do
        /bin/kill -s HUP $i
      done
  fi
}

while [ $monitor == 1 ]
    do
        tas_count=`ps -x | grep IPMITAS | grep -v grep | wc -l | sed 's/ *//g'`

        if [ $tas_count -eq 0 ]; then
            timestamp=`date`
            echo "[$timestamp]TAS shutdown unexpectedly, restarting TAS now..." >> $TAS_LOG
            echo $?
            recover_tas
        else
            sleep 10
        fi
done


