#!/bin/bash

LOCK_F=/var/lock/hbase-thrift-status.lock
if [ -f $LOCK_F ] ; then
    NOW=$( date )
    echo "${NOW} - Altro check in corso " >>/var/log/hbase/hbase-thrift-status.log 2>&1
    exit 0
fi

touch $LOCK_F
echo $$ >> $LOCK_F
S_STATUS=$( service hbase-thrift status )
S_RETVAL=$?

if [ $S_RETVAL -ne 0 ] ; then
    NOW=$( date )
    echo -n ${NOW} >>/var/log/hbase/hbase-thrift-status.log 2>&1
    service hbase-thrift start >>/var/log/hbase/hbase-thrift-status.log 2>&1
fi
rm -f $LOCK_F
exit 0
