我正在尝试从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来运行它。
有什么想法吗?
答案 0 :(得分:0)
这已通过以下步骤解决。
主管配置:
[program:analytics]
command = gunicorn analytics.wsgi:application --name analytics --workers 4 --user=ubuntu --timeout=3600 --bind 127.0.0.1:8000 ; Command to start app
user = ubuntu ; User to run as
stdout_logfile = /home/code/example/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,PYTHONPATH=/home/ubuntu/code/current/analytics/bin/python ; Set UTF-8 as default encoding