#!/bin/sh

#############################################
# que delete script
#############################################
LANG=C;export LANG
SCRIPT_DIR=`dirname $0`
LOG=${SCRIPT_DIR}/log/daedmon_check_`date +%Y%m%d`
UNAME=`uname -n`

# global.cof load
LANG=C;export LANG
SCRIPT_DIR=`dirname $0`
. ${SCRIPT_DIR}/../global.conf

ERROR_QUE=${ROOT}/que/daemon_error/${UNAME}_`date +%Y%m%d`

## ecron_monitord check

DAEMON_CHECK=`ps -ef | grep ${ROOT}/sbin/ecron_monitord | grep -v grep`

if [ "${DAEMON_CHECK}" = "" ];then
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_monitord don't running !! ${UNAME}" >> ${LOG}
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_daemon_check.sh: ecron_monitord don't running !!" ${UNAME} >> ${ERROR_QUE}

 if [ -f /tmp/ecron_monitord_lock ];then
   rm /tmp/ecron_monitord_lock
 fi

 ${ROOT}/sbin/ecron_monitord &
fi

sleep 2

DAEMON_CHECK=`ps -ef | grep ${ROOT}/sbin/ecron_monitord | grep -v grep`
if [ "${DAEMON_CHECK}" = "" ];then
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_monitord can't start !!" >> ${LOG}
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_daemon_check.sh: ecron_monitord can't start !! ${UAME}" >> ${ERROR_QUE}
fi


## ecron_mirrord check

DAEMON_CHECK=`ps -ef | grep ${ROOT}/sbin/ecron_mirrord | grep -v grep`

if [ "${DAEMON_CHECK}" = "" ];then
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_mirrord don't running !! ${UNAME}" >> ${LOG}
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_daemon_check.sh: ecron_mirrord don't running !!" ${UNAME} >> ${ERROR_QUE}

 if [ -f /tmp/ecron_mirrord_lock ];then
   rm /tmp/ecron_mirrord_lock
 fi

 ${ROOT}/sbin/ecron_mirrord &
fi

sleep 2

DAEMON_CHECK=`ps -ef | grep ${ROOT}/sbin/ecron_mirrord | grep -v grep`
if [ "${DAEMON_CHECK}" = "" ];then
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_mirrord can't start !!" >> ${LOG}
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_daemon_check.sh: ecron_mirrord can't start !! ${UAME}" >> ${ERROR_QUE}
fi

## ecron_messaged check

DAEMON_CHECK=`ps -ef | grep ${ROOT}/sbin/ecron_messaged | grep -v grep`

if [ "${DAEMON_CHECK}" = "" ];then
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_messaged don't running !! ${UNAME}" >> ${LOG}
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_daemon_check.sh: ecron_messaged don't running !!" ${UNAME} >> ${ERROR_QUE}

 if [ -f /tmp/ecron_messaged_lock ];then
   rm /tmp/ecron_messaged_lock
 fi

 ${ROOT}/sbin/ecron_messaged &
fi

sleep 2

DAEMON_CHECK=`ps -ef | grep ${ROOT}/sbin/ecron_messaged | grep -v grep`
if [ "${DAEMON_CHECK}" = "" ];then
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_messaged can't start !!" >> ${LOG}
 echo "`date +%Y/%m/%d` `date +%H:%M:%S` ecron_daemon_check.sh: ecron_messaged can't start !! ${UAME}" >> ${ERROR_QUE}
fi

exit 0
