概述
crontab -e:
*/1 * * * * /bin/bash /usr/local/sbin/check_hitpaw.sh 1.2.1 8089 &> /dev/null
check_hitpaw.sh:
#!/bin/bash
## check RegCode running status and repair
source /etc/profile;
service_tmp=0
service="hitpaw-online"
version=$1
port=$2
service_log="/var/log/$service/$version/check_$service.log"
test -d `dirname $service_log` &> /dev/null || mkdir -p `dirname $service_log`
service_check() {
test -e /data/versions/hitpaw/$version/$service &> /dev/null
result=$?
if [ $result -ne 0 ];then
service_tmp=0;
echo -e "n This is not $service machine! n"
else
service_tmp=1;
echo -e "n This is $service machine! n"
fi
if [ $service_tmp -eq 1 ];then
ps -ef |grep $service |grep -v grep &> /dev/null
service_status=$?
nc -vz -w 1 127.0.0.1 $port &> /dev/null
service_port_status=$?
curl -I http://127.0.0.1:$port?ischeck=1 &> /dev/null
http_status=$?
if [ $service_status -ne 0 -o $service_port_status -ne 0 -o $http_status -ne 0 ];then
echo -e "n" >> $service_log
echo "service $service restart in `date +"%F %T"`" >> $service_log
kill -9 `lsof -i:$port |grep -v PID |awk '{print $2}'` >> $service_log
kill -9 `ps -ef |grep $service |grep -v grep |awk '{print $2}'` >> $service_log
cd /data/versions/hitpaw/$version/
nohup ./$service &>> $service_log &
echo -e "n" >> $service_log
fi
fi
}
#process service check
step=2 #间隔的秒数,不能大于60
for (( i = 0; i < 60; i=(i+step) )); do
service_check
sleep $step
done
exit 0
最后
以上就是满意小刺猬为你收集整理的go 服务挂掉自动重启脚本的全部内容,希望文章能够帮你解决go 服务挂掉自动重启脚本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复