系统和软件环境 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
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.