Uwsgi Upstart- 虚拟环境变量无法访问

3
我正在使用Django 1.6和Uwsgi,不想以emperor模式运行Uwsgi,而是想将其作为upstart任务运行。我的Django网站在虚拟环境中。除了从.virtualenvs/community/bin/activate提取的一些变量用于settings/production.py之外,一切都很顺利。从upstart运行uwsgi时,它能够无问题地访问虚拟环境。然而,这些变量在环境中不可用。如何使变量在从upstart运行uwsgi时处于虚拟环境中?
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

可以翻译为:

根@社区:/家庭/社区/uwsgi# 猫/ 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个回答

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

请参见本书的这一章节:“Upstart入门,食谱和最佳实践”


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接