#!/bin/sh
# service check
# ---------------------------------------------- #


##### Main routine ###############################

# Function read
. ${INST_HOME}/function.sh

##### TRAP #######################################
# Deny Ctrl+C
trap 'echo "Deny Ctrl+C"' 1 2 3 15

# init
initialize

# result init
FLAG=0
declare -a SERVICE_LIST
svrCnt=0


# START
#echo_sp "${PROCESS_CHECK}."
#write_log "${SMX_PROCESSCHECK_START}"

##### stopping process check ###########################################################
#----- Auth check ------#
$ps $PS_OPT | $grep "$AUTH_CMD" | $grep -v 'grep' > /dev/null
if [ $? -eq 0 ] ; then
  FLAG=1
  SERVICE_LIST[$svrCnt]="    ${AUTHSERVER}"
  svrCnt=`expr $svrCnt + 1`
fi
#echo_sp "."

#----- Admin check ------#
$ps $PS_OPT | $grep "$ADMIN_CMD" | $grep -v 'grep' > /dev/null
if [ $? -eq 0 ] ; then
  FLAG=1
  SERVICE_LIST[$svrCnt]="    ${ADMINSERVER}"
  svrCnt=`expr $svrCnt + 1`
fi
#echo_sp "."

#----- Radius check ------#
$ps $PS_OPT | $grep "$RADIUS_CMD" | $grep -v 'grep' > /dev/null
if [ $? -eq 0 ] ; then
  FLAG=1
  SERVICE_LIST[$svrCnt]="    ${RADIUSSERVER}"
  svrCnt=`expr $svrCnt + 1`
fi
#echo_sp "."

#----- EasySetup check ------#
$ps $PS_OPT | $grep "$EZS_CMD" | $grep -v 'grep' > /dev/null
if [ $? -eq 0 ] ; then
  FLAG=1
  SERVICE_LIST[$svrCnt]="    ${EASYSETUP}"
  svrCnt=`expr $svrCnt + 1`
fi
#echo_sp "."

#----- Cron check ------#
$ps $PS_OPT | $grep "$CRON_CMD" | $grep -v 'grep' > /dev/null
if [ $? -eq 0 ] ; then
  FLAG=1
  SERVICE_LIST[$svrCnt]="    ${CRON}"
  svrCnt=`expr $svrCnt + 1`
fi
#echo_sp "."

# result
if [ $svrCnt -ne 0 ] ; then
  $echo "${OCCURED_ERROR}"
  $echo " "
  #arize_err "dmy" "${SMX_STATUS_MISS}"
  
  msg_err "${STOPPROCESS_EXIST}" \
            "${THEREPROCESS_STOPNEED}" \
            " " \
            "${SERVICE_LIST[0]}" \
            "${SERVICE_LIST[1]}" \
            "${SERVICE_LIST[2]}" \
            "${SERVICE_LIST[3]}" \
            "${SERVICE_LIST[4]}" \
            " " \
            "<!> ${INST_PREPARE}" \
            "    ${STOP_COMMAND_EXCUTE}" \
            "     ( ${ROOTUSER_COMMAND} )" \
            " " \
            "${COMMAND}: [ ${INST_HOME}/${STOP_ALL_CMD} ]" \
            " "
  
  $echo ""
  
fi

exit ${FLAG}