#!/bin/bash
# Program
#          Program that will start and kill Supermicro thin-agent service
# History:
# 2014/1/23  billw
# chkconfig: 345 99 01
# description: Supermicro Thin-Agent service

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
prog="Thin-Agent WatchDog"
TAS_BIN="/opt/supermicro/IPMITAS"
TAS_LOG="/opt/supermicro/tas_system_crush.log"
monitor=$1

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

watchdog() {
    while [ $monitor == 1 ]
    do
        if pgrep -f IPMITAS > /dev/null ; then
	    sleep 10
        else            
            echo "[$(date)]TAS shutdown unexpectedly, restarting TAS now..." >> $TAS_LOG
            start
        fi
    done
}

watchdog

