我正在尝试从 gunicorn 和 supervisord 运行 Django 应用程序。我已经将 bash 脚本配置为从 gunicorn 运行应用程序,该应用程序运行良好,并且我能够看到 GUI,但是当我尝试从 supervisorctl 启动此应用程序时。我看不到 GUI。但是,Gunicorn 进程正在运行。
gunicorn_start2
#!/bin/bash
export ANALYTICS_ENV="dev"
NAME="analytics" # Name of the application
DJANGODIR=/home/ubuntu/code/current/analytics/analytics/analysis/ # Django project directory
SOCKFILE=/home/ubuntu/code/current/analytics/analytics/run/gunicorn.sock # we will communicte using this unix socket
USER=ubuntu # the user to run as
GROUP=ubuntu # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=analytics.settings # which settings file should Django use
DJANGO_WSGI_MODULE=analytics.wsgi # WSGI module name
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
echo $DJANGODIR
source /home/ubuntu/code/current/analytics/analytics/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
#export PYTHONPATH=$DJANGODIR:$PYTHONPATH
#export PYTHONPATH=/home/ubuntu/code/analytics/bin/python
# 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 /home/ubuntu/code/current/analytics/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=all \
--log-file=-
gunicorn_start.conf
[program:analytics]
command = bash /home/ubuntu/code/current/analytics/analytics/analysis/gunicorn_start2 ; Command to start app
user = ubuntu ; User to run as
stdout_logfile = /home/ubuntu/code/current/analytics/analytics/analysis/gunicorn_start2.log ; Where to write log messages
redirect_stderr = true ; Save stderr in the same log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8,ANALYTICS_ENV=dev ; Set UTF-8 as default encoding
Gunicorn 进程:
(analytics) ubuntu@ip-172-31-25-151:~/code/current/analytics/analytics/analysis$ ps aux | grep [g]unicorn
ubuntu 16039 0.3 0.9 57152 18436 ? S 14:47 0:00 /home/ubuntu/code/current/analytics/bin/python2 /home/ubuntu/code/current/analytics/bin/gunicorn analytics.wsgi:application --name analytics --workers 3 --user=ubuntu --group=ubuntu --bind=unix:/home/ubuntu/code/current/analytics/analytics/run/gunicorn.sock --log-level=all --log-file=-
ubuntu 16050 1.1 2.3 276744 48792 ? Sl 14:47 0:00 /home/ubuntu/code/current/analytics/bin/python2 /home/ubuntu/code/current/analytics/bin/gunicorn analytics.wsgi:application --name analytics --workers 3 --user=ubuntu --group=ubuntu --bind=unix:/home/ubuntu/code/current/analytics/analytics/run/gunicorn.sock --log-level=all --log-file=-
ubuntu 16053 1.1 2.3 276760 47212 ? Sl 14:47 0:00 /home/ubuntu/code/current/analytics/bin/python2 /home/ubuntu/code/current/analytics/bin/gunicorn analytics.wsgi:application --name analytics --workers 3 --user=ubuntu --group=ubuntu --bind=unix:/home/ubuntu/code/current/analytics/analytics/run/gunicorn.sock --log-level=all --log-file=-
ubuntu 16056 1.1 2.3 276768 47228 ? Sl 14:47 0:00 /home/ubuntu/code/current/analytics/bin/python2 /home/ubuntu/code/current/analytics/bin/gunicorn analytics.wsgi:application --name analytics --workers 3 --user=ubuntu --group=ubuntu --bind=unix:/home/ubuntu/code/current/analytics/analytics/run/gunicorn.sock --log-level=all --log-file=-
(analytics) ubuntu@ip-172-31-25-151:~/code/current/analytics/analytics/analysis$
似乎问题出在环境变量上。因为当我尝试运行时,python manage.py runserver
它也不起作用。但是当我跑步时,ANALYTICS_ENV=dev python manage.py runserver
它就起作用了。
但是,无论如何我都无法用 gunicorn 运行它。
任何想法?