shell 看门狗

前端之家收集整理的这篇文章主要介绍了shell 看门狗前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

应用是通过nohup java -jar xx.jar &
难免遇到unkown error 挂掉,所以有必要编写看门狗 保护一下
#!/bin/bash
now=
date ‘+%Y-%m-%d %H:%M:%S’`

grepFlag=’datawarehouseLoader.jar’
thisLog=’/loader/watchDogLog.log’

baseDir=”/loader/”
sleepTime=60

if [ ! -f “ baseDir/datawarehouseLoader.jar];thenecho baseDir/datawarehouseLoader.jar file missing,check again" >> "$thisLog”
exit
fi

user=”root”
if [ “$user” != “root” ]; then
echo “this tool must run as root
exit
fi

while [ 0 -eq 0 ]
do
now=date '+%Y-%m-%d %H:%M:%S'
ret=ps -ef | grep "$grepFlag" | grep -v grep | wc -l
if [ reteq0];thencd baseDir
echo “ nowprocessnotexists,restartprocessnow...">>" thisLog”
nohup java -jar datawarehouseLoader.jar &
echo “ nowrestartdone..@H_909_403@...">>" thisLog”
cd curDirelseecho now process exists,sleep sle@H_244_502@epTimeseconds>> thisLog”
sleep $sleepTime
fi
done
`
臭不要脸的参考自:使用bash shell脚本编写简易的看门狗watch dog – https://www.chenyudong.com/archives/bash-shell-watch-dog-auto-restart-process.html

猜你在找的Bash相关文章