我正在使用Django 1.6和Uwsgi,不想以emperor模式运行Uwsgi,而是想将其作为upstart任务运行。我的Django网站在虚拟环境中。除了从
"Django设置 production.py"
.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#