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

2016-08-23 21:12:53 +08:00
 pc10201

系统和软件环境 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
3307 次点击
所在节点    程序员
3 条回复
fcicq
2016-08-23 21:41:43 +08:00
想用这些 supervisor 就要去掉 daemon
pc10201
2016-08-24 00:52:32 +08:00
@fcicq 这个是 monit,不是 supervisor ,而且两个原理不同, monit 是直接监控 pid 的
mephisto
2016-08-24 10:45:29 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/301300

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX