Permalink
Browse files

Refactor jumpstart into a Django app.

  • Loading branch information...
1 parent e095e04 commit 8d5cc34334ea9a686069544661775739c98666c9 @onyxfish onyxfish committed Jun 12, 2012
View
10 application_jumpstart.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+import os
+
+import django.core.handlers.wsgi
+
+os.environ["DJANGO_SETTINGS_MODULE"] = "config.jumpstart.settings"
+
+application = django.core.handlers.wsgi.WSGIHandler()
+
View
0 config/jumpstart/__init__.py
No changes.
View
28 config/jumpstart/settings.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+from config.settings import *
+from config.deployed.settings import *
+
+# Running in deployed mode
+SETTINGS = 'jumpstart'
+
+INSTALLED_APPS = (
+ 'longerusername',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.admin',
+ 'django.contrib.humanize',
+ 'django.contrib.sites',
+ 'django.contrib.staticfiles',
+
+ 'south',
+ 'tastypie',
+ 'djcelery',
+ 'compressor',
+ 'livesettings',
+
+ 'jumpstart'
+)
+
View
10 jumpstart/urls.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+from django.conf.urls.defaults import patterns, url
+
+from jumpstart import views
+
+urlpatterns = patterns('',
+ url(r'^$', views.jumpstart, name='jumpstart')
+)
+
View
34 jumpstart/application.py → jumpstart/views.py
@@ -4,25 +4,17 @@
import subprocess
import time
-from flask import Flask, render_template, request
+from django.shortcuts import render_to_response
from pytz import common_timezones
from daemon import Daemon
-# Configuration
-DEBUG = True
-TEST_MODE = False
-
PANDA_PATH = '/opt/panda'
LOCAL_SETTINGS_PATH = '%s/local_settings.py' % PANDA_PATH
RESTART_SCRIPT_PATH = '%s/jumpstart/restart-uwsgi.sh' % PANDA_PATH
DAEMON_PID_PATH = '/tmp/jumpstart-restart.pid'
DAEMON_LOG_PATH = '/var/log/jumpstart-restart.log'
-# Setup
-app = Flask(__name__)
-app.debug = DEBUG
-
class RestartDaemon(Daemon):
"""
Simple daemon so that a uwsgi process can reboot itself
@@ -36,29 +28,21 @@ def run(self):
if os.path.exists(self.pidfile):
os.remove(self.pidfile)
-@app.route('/', methods=['GET', 'POST'])
-def index():
+def jumpstart(request):
if request.method == 'POST':
- timezone = request.form['timezone']
+ timezone = request.POST['timezone']
- if not TEST_MODE:
- with open(LOCAL_SETTINGS_PATH, 'w') as f:
- f.write("TIME_ZONE = '%s'\n" % timezone)
+ with open(LOCAL_SETTINGS_PATH, 'w') as f:
+ f.write("TIME_ZONE = '%s'\n" % timezone)
- daemon = RestartDaemon(DAEMON_PID_PATH, stdout=DAEMON_LOG_PATH)
- daemon.start()
+ daemon = RestartDaemon(DAEMON_PID_PATH, stdout=DAEMON_LOG_PATH)
+ daemon.start()
- return render_template('wait.html')
+ return render_to_response('wait.html')
else:
context = {
'timezones': common_timezones
}
- return render_template('index.html', **context)
-
-if __name__ == '__main__':
- # When using Runserver, enable TEST_MODE
- TEST_MODE = True
-
- app.run(host='0.0.0.0', port=8000)
+ return render_to_response('index.html', **context)
View
4 setup_panda/uwsgi_jumpstart.conf
@@ -1,9 +1,11 @@
description "uWSGI jumpstart server for PANDA"
+description "uWSGI Jumpstart server for PANDA"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
+env DEPLOYMENT_TARGET=jumpstart
script
rm -rf /var/run/uwsgi
mkdir -p /var/run/uwsgi
- /usr/local/bin/uwsgi --socket /var/run/uwsgi/uwsgi.sock --chmod-socket --module application --callable app --chdir /opt/panda/jumpstart -p 1 --logto /var/log/uwsgi.log
+ /usr/local/bin/uwsgi --socket /var/run/uwsgi/uwsgi.sock --chmod-socket --module application_jumpstart --pythonpath /opt/panda -p 1 --logto /var/log/uwsgi.log
end script

0 comments on commit 8d5cc34

Please sign in to comment.