mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
after multiple attempts it's easier to just reload the app. People using
mange.py have to use USR2 signal if they want to upgrade the django version instread of HUP. On the other hand, upgrading django version with HUP is possible with gunicorn_django command.
This commit is contained in:
parent
6e13a0fcd9
commit
fcab6bc144
@ -7,83 +7,90 @@ DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (
|
||||
# ('Your Name', 'your_email@domain.com'),
|
||||
('benoitc', 'bchesneau@gmail.com'),
|
||||
)
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||
DATABASE_NAME = 'test.db' # Or path to database file if using sqlite3.
|
||||
DATABASE_USER = '' # Not used with sqlite3.
|
||||
DATABASE_PASSWORD = '' # Not used with sqlite3.
|
||||
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
|
||||
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': 'test.db',
|
||||
}
|
||||
}
|
||||
|
||||
# Local time zone for this installation. Choices can be found here:
|
||||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||
# although not all choices may be available on all operating systems.
|
||||
# If running in a Windows environment this must be set to the same as your
|
||||
# system time zone.
|
||||
TIME_ZONE = 'America/Chicago'
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
# If you set this to False, Django will make some optimizations so as not
|
||||
# to load the internationalization machinery.
|
||||
USE_I18N = True
|
||||
|
||||
# Absolute path to the directory that holds media.
|
||||
# Example: "/home/media/media.lawrence.com/"
|
||||
USE_L10N = True
|
||||
|
||||
MEDIA_ROOT = ''
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash if there is a path component (optional in other cases).
|
||||
# Examples: "http://media.lawrence.com", "http://example.com/media/"
|
||||
MEDIA_URL = ''
|
||||
|
||||
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
||||
# trailing slash.
|
||||
# Examples: "http://foo.com/media/", "/media/".
|
||||
ADMIN_MEDIA_PREFIX = '/media/'
|
||||
STATIC_ROOT = ''
|
||||
|
||||
# Make this unique, and don't share it with anybody.
|
||||
SECRET_KEY = '+$ke3e&)ai+p2vzg@!ku9m=xq=b02-jam9m=_w%n*ys@a8r8va'
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
ADMIN_MEDIA_PREFIX = '/static/admin/'
|
||||
|
||||
STATICFILES_DIRS = (
|
||||
)
|
||||
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
)
|
||||
|
||||
SECRET_KEY = 'c-u@jrg$dy)g7%)=jg)c40d0)4z0b%mltvtu)85l1&*(zwau(f'
|
||||
|
||||
# List of callables that know how to import templates from various sources.
|
||||
TEMPLATE_LOADERS = (
|
||||
'django.template.loaders.filesystem.load_template_source',
|
||||
'django.template.loaders.app_directories.load_template_source',
|
||||
# 'django.template.loaders.eggs.load_template_source',
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
)
|
||||
|
||||
|
||||
FILE_UPLOAD_HANDLERS = (
|
||||
"django.core.files.uploadhandler.TemporaryFileUploadHandler",
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'djangotest.urls'
|
||||
|
||||
TEMPLATE_DIRS = (
|
||||
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
|
||||
# Always use forward slashes, even on Windows.
|
||||
# Don't forget to use absolute paths, not relative paths.
|
||||
)
|
||||
TEMPLATE_DIRS = ()
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'djangotest.testing',
|
||||
'gunicorn'
|
||||
'gunicorn',
|
||||
)
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': False,
|
||||
'handlers': {
|
||||
'mail_admins': {
|
||||
'level': 'ERROR',
|
||||
'class': 'django.utils.log.AdminEmailHandler'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.request': {
|
||||
'handlers': ['mail_admins'],
|
||||
'level': 'ERROR',
|
||||
'propagate': True,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
4
examples/frameworks/djangotest/testing/models.py
Executable file → Normal file
4
examples/frameworks/djangotest/testing/models.py
Executable file → Normal file
@ -1 +1,3 @@
|
||||
# Create your models here.
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
# This file is part of gunicorn released under the MIT license.
|
||||
# See the NOTICE for more information.
|
||||
|
||||
import imp
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
@ -91,14 +92,15 @@ class DjangoApplication(Application):
|
||||
error = s.read()
|
||||
sys.stderr.write("One or more models did not validate:\n%s" % error)
|
||||
sys.stderr.flush()
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
def load(self):
|
||||
from django.conf import ENVIRONMENT_VARIABLE
|
||||
from django.core.handlers.wsgi import WSGIHandler
|
||||
|
||||
|
||||
os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname
|
||||
# setup environ
|
||||
|
||||
self.setup_environ()
|
||||
self.validate()
|
||||
self.activate_translation()
|
||||
@ -113,10 +115,30 @@ class DjangoApplicationCommand(DjangoApplication):
|
||||
self.options = options
|
||||
self.admin_media_path = admin_media_path
|
||||
self.callable = None
|
||||
|
||||
self.init()
|
||||
self.do_load_config()
|
||||
|
||||
for k, v in self.options.items():
|
||||
if k.lower() in self.cfg.settings and v is not None:
|
||||
self.cfg.set(k.lower(), v)
|
||||
|
||||
def init(self):
|
||||
self.settings_modname = os.environ[ENVIRONMENT_VARIABLE]
|
||||
self.project_name = self.settings_modname.split('.')[0]
|
||||
self.project_path = os.getcwd()
|
||||
|
||||
self.do_load_config()
|
||||
# remove all modules related to djano
|
||||
for modname, mod in sys.modules.items():
|
||||
if 'settings' in modname.split('.') or \
|
||||
modname.startswith(self.project_name):
|
||||
del sys.modules[modname]
|
||||
|
||||
# add the project path to sys.path
|
||||
sys.path.insert(0, self.project_path)
|
||||
sys.path.append(os.path.normpath(os.path.join(self.project_path,
|
||||
os.pardir)))
|
||||
|
||||
|
||||
def load_config(self):
|
||||
self.cfg = Config()
|
||||
@ -129,6 +151,7 @@ class DjangoApplicationCommand(DjangoApplication):
|
||||
"__doc__": None,
|
||||
"__package__": None
|
||||
}
|
||||
|
||||
try:
|
||||
execfile(self.config_file, cfg, cfg)
|
||||
except Exception:
|
||||
@ -145,31 +168,24 @@ class DjangoApplicationCommand(DjangoApplication):
|
||||
except:
|
||||
sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
|
||||
raise
|
||||
|
||||
|
||||
for k, v in self.options.items():
|
||||
if k.lower() in self.cfg.settings and v is not None:
|
||||
self.cfg.set(k.lower(), v)
|
||||
|
||||
def setup_environ(self):
|
||||
for modname in sys.modules.keys():
|
||||
if modname.startswith('django') or \
|
||||
'settings' in modname.split('.'):
|
||||
del sys.modules[modname]
|
||||
|
||||
# add the project path to sys.path
|
||||
sys.path.insert(0, self.project_path)
|
||||
sys.path.append(os.path.normpath(os.path.join(self.project_path,
|
||||
os.pardir)))
|
||||
super(DjangoApplicationCommand, self).setup_environ()
|
||||
|
||||
def load(self):
|
||||
# setup environ
|
||||
self.setup_environ()
|
||||
self.validate()
|
||||
self.activate_translation()
|
||||
|
||||
from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
|
||||
for n in sys.modules.keys():
|
||||
if 'settings' in n or 'djangotest' in n:
|
||||
print n
|
||||
from django.conf import ENVIRONMENT_VARIABLE
|
||||
from django.core.handlers.wsgi import WSGIHandler
|
||||
os.environ[ENVIRONMENT_VARIABLE] = self.settings_modname
|
||||
|
||||
self.setup_environ()
|
||||
self.validate()
|
||||
self.activate_translation()
|
||||
|
||||
from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
|
||||
|
||||
try:
|
||||
return AdminMediaHandler(WSGIHandler(), self.admin_media_path)
|
||||
@ -186,7 +202,7 @@ class DjangoApplicationCommand(DjangoApplication):
|
||||
error_text = str(e)
|
||||
sys.stderr.write(self.style.ERROR("Error: %s" % error_text) + '\n')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def run():
|
||||
"""\
|
||||
The ``gunicorn_django`` command line runner for launching Django
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user