V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
pc10201
V2EX  ?  程序员

monit 对进程进行监控,死活跑不起来,请老司机解救

  •  
  •   pc10201 · 2016-08-23 21:12:53 +08:00 · 3179 次点击
    这是一个创建于 2805 天前的主题,其中的信息可能已经有所发展或是发生改变。

    腾讯云最新优惠活动来了:云产品限时1折,云服务器低至88元/年 ,点击这里立即抢购:9i0i.cn/qcloud,更有2860元代金券免费领取,付款直接抵现金用,点击这里立即领取:9i0i.cn/qcloudquan

    (福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

    系统和软件环境 CentOS 7 monit(yum 安装,版本 5.14)

    手动运行 /bin/bash /data/wwwroot/xxx.com/xxx/xxx.sh start 总能成功

    用 monit 运行总是显示执行失败

    配置文件

    check process xxx with pidfile /var/run/xxx.pid
        start program = "/bin/bash /data/wwwroot/xxx.com/xxx/xxx.sh start"
        stop program = "/bin/bash /data/wwwroot/xxx.com/xxx/xxx.sh stop"
    

    xxx.sh 脚本

    #!/bin/bash
    
    NAME="xxx"                                  # Name of the application
    DJANGODIR=/data/wwwroot/xxx.com/xxx             # Django project directory
    SOCKFILE=/tmp/${NAME}.sock  # we will communicte using this unix socket
    PIDFILE=/var/run/${NAME}.pid
    USER=www                                        # the user to run as
    GROUP=www                                     # the group to run as
    NUM_WORKERS=3                                     # how many worker processes should Gunicorn spawn
    DJANGO_SETTINGS_MODULE=xxx.settings             # which settings file should Django use
    DJANGO_WSGI_MODULE=xxx.wsgi                     # WSGI module name
    
    start() {
    echo "Starting $NAME as `whoami`"
    
    # Activate the virtual environment
    cd $DJANGODIR
    source .venv/bin/activate
    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
    export PYTHONPATH=$DJANGODIR:$PYTHONPATH
    
    # Create the run directory if it doesn't exist
    RUNDIR=$(dirname $SOCKFILE)
    test -d $RUNDIR || mkdir -p $RUNDIR
    
    # Start your Django Unicorn
    # Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
    exec gunicorn ${DJANGO_WSGI_MODULE}:application \
      --name $NAME \
      --workers $NUM_WORKERS\
      --user=$USER --group=$GROUP \
      --bind=unix:$SOCKFILE \
      --pid=$PIDFILE \
      --worker-class=meinheld.gmeinheld.MeinheldWorker --daemon
    }
    
    stop() {
     kill `cat $PIDFILE`
    }
    
    case $1 in
        start)
            start
           ;;
         stop)
          stop
           ;;
         *)
           echo "usage: ${NAME} {start|stop}" ;;
     esac
     exit 0
    
    3 条回复  ?  2016-08-24 10:45:29 +08:00
    fcicq
        1
    fcicq  
       2016-08-23 21:41:43 +08:00
    想用这些 supervisor 就要去掉 daemon
    pc10201
        2
    pc10201  
    OP
       2016-08-24 00:52:32 +08:00
    @fcicq 这个是 monit,不是 supervisor ,而且两个原理不同, monit 是直接监控 pid 的
    mephisto
        3
    mephisto  
       2016-08-24 10:45:29 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   941 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:00 · PVG 05:00 · LAX 14:00 · JFK 17:00
    Developed with CodeLauncher
    ? Do have faith in what you're doing.


    http://www.vxiaotou.com