【发布时间】:2014-06-15 18:01:29
【问题描述】:
我正在使用 Django 1.6 和 Uwsgi。我不想在皇帝模式下运行 Uwsgi。我想将 Uwsgi 作为新贵的工作来运行。我的 Django 站点位于虚拟环境中。一切都很好,除了我有一些从.virtualenvs/community/bin/activate 中提取的变量,这些变量在settings/production.py 中使用。从新贵运行 uwsgi,它能够毫无问题地访问虚拟环境。但是,这些变量在环境中不可用。当 uwsgi 从 upstart 运行时,如何才能到达虚拟环境中变量的位置?
root@community:/home/community/uwsgi# cat /home/community/.virtualenvs/community/bin/activate
export DB_NAME="blah"
export DB_USER="foo"
export DB_PASS="bar"
export DB_HOST="localhost"
Django 设置 production.py
########## DATABASE CONFIGURATION
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': get_env_variable('DB_NAME'), # Or path to database file if using sqlite3.
'USER': get_env_variable('DB_USER'), # Not used with sqlite3.
'PASSWORD': get_env_variable('DB_PASS'), # Not used with sqlite3.
'HOST': get_env_variable('DB_HOST'), # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}, }
root@community:/home/community/uwsgi# cat community_forums.ini
[uwsgi]
chdir = /home/community/community-forums/bot_server
module = bot_server.wsgi:application
env = DJANGO_SETTINGS_MODULE=bot_server.settings.production
master = 1
pidfile = /tmp/project-master.pid
socket = 127.0.0.1:3031
processes = 5
harakiri = 20
max-requests = 5000
vacuum = 1
logto = /var/tmp/uwsgi.log
virtualenv = /home/community/.virtualenvs/community
root@community:/home/community/uwsgi# cat /etc/init/uwsgi.conf
#This version is for Community Servic
description "uwsgi tiny instance"
start on runlevel [2345]
stop on runlevel [06]
exec uwsgi --die-on-term --ini /home/community/uwsgi/community_forums.ini
root@community:/home/community/uwsgi#
【问题讨论】: