Skip to content

Commit

Permalink
Scottx611x/django 1.7 upgrade apache settings fix (#1544)
Browse files Browse the repository at this point in the history
* Allow for env vars set by Apache to be accessible by Django

* Change "fail-safe" to use our production settings

* Add useful comment

* Switch back to `dev`

* Change Apache conf template to not use `SetEnv` and be able to handle different wsgi configs

* Split into different wsgi config files to move away from SetEnv hack

* Update fabfile accordingly
  • Loading branch information
scottx611x committed Dec 5, 2016
1 parent 486116a commit 94f51b4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
7 changes: 3 additions & 4 deletions deployment/apache.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

WSGIPythonHome <%= @virtualenv %>

SetEnv DJANGO_SETTINGS_MODULE <%= @django_settings_module %>

<VirtualHost *:80>
ServerName <%= @site_url %>
Expand All @@ -16,12 +14,13 @@ SetEnv DJANGO_SETTINGS_MODULE <%= @django_settings_module %>
<% end %>

<Directory <%= @django_root %>/config>
<Files wsgi.py>
<Files wsgi*.py>
Order deny,allow
Require all granted
</Files>
</Directory>
WSGIScriptAlias / <%= @django_root %>/config/wsgi.py

WSGIScriptAlias / <%= @django_root %>/config/wsgi_<%= @django_settings_module.split('.')[-1] %>.py

WSGIDaemonProcess refinery user=<%= @app_user %> group=<%= @app_group %> \
python-path=<%= @django_root %>:<%= @virtualenv %>/lib/python2.7/site-packages
Expand Down
18 changes: 10 additions & 8 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,22 @@ def conf(mode=None):
env.shell_before = "export DJANGO_SETTINGS_MODULE=config.settings.*"
env.shell_after = \
"export DJANGO_SETTINGS_MODULE=config.settings.{}".format(mode)
env.apache_before = "SetEnv DJANGO_SETTINGS_MODULE config.settings.*"
env.apache_after = \
"SetEnv DJANGO_SETTINGS_MODULE config.settings.{}".format(mode)
env.apache_before = "wsgi_.*.py"
if mode == "prod":
env.apache_after = "wsgi_prod.py"
else:
env.apache_after = "wsgi_dev.py"
# stop supervisord and Apache
with prefix("workon {refinery_virtualenv_name}".format(**env)):
run("supervisorctl shutdown")
sudo("/usr/sbin/service apache2 stop")
# update DJANGO_SETTINGS_MODULE
sed('/home/vagrant/.profile', before=env.shell_before,
after=env.shell_after, backup='')
# update WSGIScriptAlias value
sed('/etc/apache2/sites-available/001-refinery.conf',
before=env.apache_before, after=env.apache_after, use_sudo=True,
backup='')
before=env.apache_before, after=env.apache_after, backup='',
use_sudo=True)
# update static files
with cd(env.refinery_ui_dir):
run("grunt make")
Expand Down Expand Up @@ -138,8 +141,7 @@ def update_refinery():
run("{refinery_app_dir}/manage.py collectstatic --clear --noinput"
.format(**env))
run("supervisorctl reload")
with cd(env.refinery_project_dir):
run("touch {refinery_app_dir}/config/wsgi.py".format(**env))
run("touch {refinery_app_dir}/config/wsgi_*.py".format(**env))


@task(alias="relaunch")
Expand All @@ -166,4 +168,4 @@ def relaunch_refinery(dependencies=False, migrations=False):
.format(**env))
run("supervisorctl restart all")
with cd(env.refinery_project_dir):
run("touch {refinery_app_dir}/config/wsgi.py".format(**env))
run("touch {refinery_app_dir}/config/wsgi_*.py".format(**env))
14 changes: 0 additions & 14 deletions refinery/config/wsgi.py

This file was deleted.

7 changes: 7 additions & 0 deletions refinery/config/wsgi_aws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
from django.core.wsgi import get_wsgi_application

# Set env vars to be made available to the wsgi application here
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.aws'

application = get_wsgi_application()
7 changes: 7 additions & 0 deletions refinery/config/wsgi_dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
from django.core.wsgi import get_wsgi_application

# Set env vars to be made available to the wsgi application here
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.dev'

application = get_wsgi_application()
7 changes: 7 additions & 0 deletions refinery/config/wsgi_prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
from django.core.wsgi import get_wsgi_application

# Set env vars to be made available to the wsgi application here
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.prod'

application = get_wsgi_application()

0 comments on commit 94f51b4

Please sign in to comment.