程序寫好了,得監控上,嘿嘿。研究出來如下代碼,進行使用,嘿嘿。 我這裡每個進程只需要一個實例,即使實例有多個,也會使用不同的配置文件區分開來,否則不知道程序的哪個實例掛了, 不說了,附上代碼,自己看吧。重點在config那塊兒,我寫的是相對目錄哦。嘿嘿
- #!/bin/bash
- #func checkProcessName
- # param1 threadname param2 user
- CheckProcess()
- {
- PROCESS_NAME="$1"
- if [ "$PROCESS_NAME" = "" ];then
- return 1;
- fi
- USER_NAME="$2"
- PROCESS_NUM=0
- COMMAND_STR=""
- if [ "$USER_NAME" = "" ];then
- PROCESS_NUM=`ps -elf|grep "${PROCESS_NAME}" |grep -v "grep"|wc -l`
- else
- PROCESS_NUM=`ps -u "${USER_NAME}" -lf |grep "${PROCESS_NAME}" |grep -v "grep"|wc -l`
- fi
-
- if [ ${PROCESS_NUM} -eq 1 ];then
- return 0
- else
- return 1
- fi
- }
- #config
- process=(\
- "./servers servers.ini"\
- "./serverc serverc.ini"\
- )
- # "./baike_fspage baike_fspage.ini"\
- processdir=(\
- "/server/servers"\
- "/server/serverc"\
- )
-
- # "/baiketrans" \
- curdir=`pwd`
- #main
- while [ 1 ] ;do
- sleep 10
- for i in $( seq 0 $[${#process[@]}-1] )
- do
- CheckProcess "${process[$i]}" "jianghi"
- notLive=$?
- if [ $notLive -eq 1 ];
- then
- cd ${curdir}${processdir[$i]}
- if [ $? -eq 0 ];then
- ./startup.sh
- echo "[" `date "+%Y/%m/%d %k:%M:%S"` "]" `pwd`/startup.sh "start..."
- else
- echo "[" `date "+%Y/%m/%d %k:%M:%S"` "] not find ${curdir}${processdir[$i]}/startup.sh "
- fi
- fi
-
- done
- done