Uwsgi Upstart-虚拟环境变量不可访问

时间:2014-04-29 16:54:46

标签: django uwsgi

我正在使用Django 1.6和Uwsgi。我不想在皇帝模式下运行Uwsgi。我想把Uwsgi作为一个暴发户的工作。我的Django站点位于虚拟环境中。除了.virtualenvs/community/bin/activate中使用settings/production.py中提取的一些变量之外,一切都很顺利。从upstart运行uwsgi,它可以访问virtualenviroment没有问题。但是,这些变量在环境中不可用。当从upstart运行uwsgi时,如何将其变为虚拟环境中变量的位置?

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#

1 个答案:

答案 0 :(得分:1)

Upstart环境变量:

#This version is for Community Servic

description "uwsgi tiny instance"

env DB_NAME="blah"
env DB_USER="foo"
env DB_PASS="bar"
env DB_HOST="localhost"

start on runlevel [2345]
stop on runlevel [06]

exec uwsgi --die-on-term --ini /home/community/uwsgi/community_forums.ini

请参阅this chapter of the book:" Upstart简介,食谱和最佳实践"