cce

#!/usr/bin/ksh

if [ `echo $0 | grep -c "/"` -gt 0 ];then
    cd ${0%/*}    
fi

#check whether config.def file exist
if [ ! -f "config.def" ]
then
writeLog "ERROR" "monitor" "the config.def file isn't exist,exit monitor application."
return 100
else
#source the config file
. ./config.def
fi

################################################################################
# name : is_process_running
# describe: check the process whether running in current user.
# parameter list: null
# input   : null
# output  : 0 success 1 failure
# rerurn  : null
# invoker : main
################################################################################
function is_process_running
{
typeset process_name="$1"

typeset -i process_num=`su - ${RUN_USER} -c "ps -ef | grep ${process_name} | grep -w ${RUN_USER} | grep -v grep | wc -l"`

if [ ${process_num} -gt 0 ]
then
echo "the process is running."
return 1
else
echo "the process is stopped."
return 0
fi
}
################################################################################
# name : main
# describe: check the jboss whether need to switch.
# the Monitor java process monitoring jboss realtime.In case the Monitor
# create a temp file in ${HOME}/monitor/log/restartFlag then need to restart jboss
# parameter list: null
# input   : null
# output  : 0 success 1 failure
# rerurn  : null
# invoker : VCS
################################################################################
function main
{
#get jboss user home path
typeset user_home=`su - ${RUN_USER} -c "env|grep ^HOME |awk -F= '{print \\$2}'"`
typeset -i is_jboss_running=0
typeset -i is_monitor_running=0

if [ "x${user_home}" = "x" ]
then
writeLog "ERROR" "monitor" "can not find the user_home(${RUN_USER}) variable."
return 100
fi

is_process_running "${jboss_process}"
if [ $? -ne 0 ]
then
is_jboss_running=1
fi

is_process_running "${monitor_process}"
if [ $? -ne 0 ]
then
is_monitor_running=1
fi

#anytime the Monitor process monitoring jboss process whether healthy.but maybe appear four scene
#scene1:jboss and Monitor process are running healthy,so return success.
#scene2:jboss process is running,but Monitor process is stopped.In this case need to restart Monitor process for monitoring jboss process,so return failed.
#scene3:jboss and Monitor process are stopped,so return failed.
#scene4:jboss is stopped,but Monitor process is running.In this case maybe Monitor process is restarting jboss process,
# so needn't to return failed in current invoke.because once Monitor process attempt to restarting jboss process failed,the Monitor process will be shutdown,
# and then jboss and Monitor process are stopped,this condition match scene3.

#the jboss and monitor process are not startup
if [ ${is_jboss_running} -eq 0 -a ${is_monitor_running} -eq 0 ]
then
writeLog "INFO" "monitor" "the jboss and monitor process are stopped."
return 100
fi

#the monitor process is running but the jboss process is stopped,maybe the monitor process is restarting jboss process
if [ ${is_jboss_running} -eq 0 -a ${is_monitor_running} -eq 1 ]
then
writeLog "INFO" "monitor" "the monitor process is running but the jboss process is stopped,maybe the monitor process is restarting jboss process."
return 110
fi

#the monitor process is stopped but the jboss process is running,must start the monitor process
if [ ${is_jboss_running} -eq 1 -a ${is_monitor_running} -eq 0 ]
then
writeLog "INFO" "monitor" "the jboss process is running but the monitor process is stopped,need to restart Monitor process."
return 100
fi

#the jboss and monitor process are running healthy
if [ ${is_jboss_running} -eq 1 -a ${is_monitor_running} -eq 1 ]
then
writeLog "INFO" "monitor" "the jboss and monitor process are running healthy."
return 110
fi
}

typeset jboss_process="org.jboss.Main"
typeset monitor_process="com.huawei.bme.monitor.MonitorMain"

main "$@"

你可能感兴趣的:(C++,c,jboss,C#,F#)