您当前的位置:首页 > 学海无涯 > 心得笔记网站首页心得笔记
Linux常用服务故障自动重启脚本
发布时间:2015-11-02作者:
示例一:
#!/bin/bash
redis_client=/usr/local/redis/bin/redis-cli
logfile=/var/log/redis.log
proc_name="redis-server" # 进程名
pid=0
proc_num() # 计算进程数
{
num=`ps -ef | grep $proc_name | grep -v grep | wc -l`
return $num
}
proc_id() #进程号
{
pid=`ps -ef | grep $proc_name | grep -v grep | awk '{print $2}'`
}
proc_num
number=$?
if [ $number -eq 0 ] ; then
echo " Server is no running,Restart... " >> $logfile
/etc/init.d/redis restart # 重启进程
proc_id # 获取新进程号
echo ${pid}, `date` >> $logfile # 将新进程号和重启时间记录
fi示例二:
#!/bin/bash
CheckURL="www.test.com"
STATUS_CODE=`curl -o /dev/null -m 10 --connect-timeout 10 -s -w %{http_code} $CheckURL`
#echo "$CheckURL Status Code:\t$STATUS_CODE"
if [ "$STATUS_CODE" = "502" ]; then
/etc/init.d/php-fpm restart
fi
关键字词:自动重启,故障,监控,linux

上一篇:PHP编译常见错误信息
下一篇:Jemalloc内存管理优化