The watchdog of the recent project has undergone three versions.
First version:
With PS-EF, if the program hangs, it starts.
A second version:
program because the runtime will not listen to the 7901 port, so it is not easy to determine whether the machine is hanging, but to determine if this port is listening
A third version:
When the 7901 port is no longer listening, the original killall in the start, each output to the content of the file to add the date, or do not know when this thing happened
#!/bin/shset +xsource env.shprmgram=scp_platformfile_name=scp_monitor.logcurrent_time= ' date + '%Y-%m-%d%H:%M:%S.%N "' echo" [${current_time}] Monitor start .... "Echo" [${current_time}] Monitor start ... ">> ${work_dir}/log/${file _name}port=7905tcplisteningnum= ' Netstat-an | grep ": $port" | awk ' $ = = ' TCP ' && $NF = = ' LISTEN ' {print $} ' | Wc-l ' if [$TCPListeningnum = 1]then{echo "[${current_time}] The $port is listening"}else{echo "[${current_time}] The port is not listening "}fiwhile [1]do current_time= ' date +"%y-%m-%d%h:%m:%s.%n "' tcplisteningnum= ' Netstat-an | grep ": $port" | awk ' $ = = ' TCP ' && $NF = = ' LISTEN ' {print $} ' | Wc-l ' if [$TCPListeningnum = 1]then{echo "[${current_time}] The ${port} is listening" >> ${work_dir}/log/${fil e_name}}else{echo "[${current_time}] The ${port} is not listening" >> ${work_dir}/log/${file_name} echo "[${ Current_time}] killall scp_platform now! ">> ${work_dir}/log/${file_name} KSCP echo "[${current_time}] Check ${prmgram} quit, now restart ${prmgram} ..." >> ${work_dir}/log/${file_name } Scp_platform&}fi Sleep 180done
The main env.sh that depend on are setting environment variables and custom variables
#bin/bashexport root=/root/scpexport work_dir=${root}export include=${root}/includeexport OTL=${INCLUDE}/otl_ Mysqlexport Ld_library_path=${root}/lib:/usr/local/libexport Ace_root=${include}export ODBCINI=/usr/local/etc/ Odbc.iniexport odbcsysini=/usr/local/etcpath=${path}:${root}/binexport pathodbcinst-jalias wk= ' cd ${ROOT} ' Alias bin = ' CD ${root}/bin ' Alias cfg= ' CD ${root}/conf ' Alias rmlog= ' Rm-rf ${root}/bin/log*.*; Rm-rf ${root}/log/*.* ' Alias lis= ' Netstat-an|grep-i 7905 ' Alias scp= ' ${root}/bin/scp_platform & ' Alias moni= ' ${ROOT }/bin/monitor.sh & ' Alias myps= ' ps-fu root|grep-v grep|grep-i SCP ' Alias mymoni= ' Ps-fu root|grep-v grep|grep-i Mon I ' Alias kscp= ' killall-9 scp_platform ' Alias kmoni= ' killall-9 monitor.sh ' isqlalias mynet= ' Netstat-an | grep 7905 ' ulimit-c unlimitedulimit-n 65530