Skip to content

Instantly share code, notes, and snippets.

@jorben
Created April 24, 2018 06:40
Show Gist options
  • Save jorben/650192c8cbdd44dadb00f04b9e391d76 to your computer and use it in GitHub Desktop.
Save jorben/650192c8cbdd44dadb00f04b9e391d76 to your computer and use it in GitHub Desktop.
Linux下为重要的进程创建监控脚本watchdog.sh
#! /bin/sh
PRO_NAME=frpc
NOW=`date +'%Y-%m-%d %H:%M:%S'`
# while true; do
NUM=`ps aux | grep ${PRO_NAME} | grep -v grep | wc -l `
if [ "${NUM}" -lt "1" ]; then
echo "${NOW} ${PRO_NAME} was dead!"
nohup ./${PRO_NAME} -c ../etc/frpc.ini &
echo "${NOW} restart ok!"
elif [ "${NUM}" -gt "1" ]; then
# 出现多个同名进程的场景,这里仅做日志记录
echo "${NOW} ${PRO_NAME} more than 1!"
fi
# 检验进程是否僵死
NUM_STAT=`ps aux | grep ${PRO_NAME} | grep -E "T|Z" | grep -v grep | wc -l`
if [ "${NUM_STAT}" -gt "0" ]; then
echo "${NOW} ${PRO_NAME} maybe dead!"
killall -9 ${PRO_NAME}
nohup ./${PRO_NAME} -c ../etc/frpc.ini &
echo "${NOW} restart ok!"
fi
# done
# set crontab
# watchdog for frpc
#* * * * * cd /usr/local/frpc/bin; sh watchdog.sh > watchdog.log 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment