zoukankan      html  css  js  c++  java
  • Linux 进程监控和自动重启的简单实现

    目的:linux 下服务器程序会因为各种原因dump掉,就会影响用户使用,这里提供一个简单的进程监控和重启功能。

    实现原理:由定时任务crontab调用脚本,脚本用ps检查进程是否存在,如果不存在则重启并写入日志

    #! /bin/sh

    host_dir=`echo ~`                                       # 当前用户根目录
    proc_name="CandyGameServer"                             # 进程名
    file_name="/Candy/log/cron.log"                         # 日志文件
    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
        cd $host_dir/CandyAT/Bin/; ./candy.sh -DZone    # 重启进程的命令,请相应修改
        proc_id                                         # 获取新进程号
        echo ${pid}, `date` >> $host_dir$file_name      # 将新进程号和重启时间记录
    fi

    下面是crontab.txt的内容:

    */1 * * * * /home/chen/CandyAT/Bin/monitor.sh 

    作者:氧气之吻
  • 相关阅读:
    如何让背景图片全屏显示
    浅谈图片如何在页面中居中显示
    clientHeight、offsetHeight 区别 笔记
    使用Flexible实现手淘H5页面的终端适配
    max(min)-device-width和max(min)-width的区别
    HTML5 meta最全使用手册
    常见浏览器兼容性问题与解决方案
    响应式设计的性能优化(转)
    移动H5前端性能优化指南
    SQL Server Profiler使用方法
  • 原文地址:https://www.cnblogs.com/yang75n/p/8351651.html
Copyright © 2011-2022 走看看