Skip to content

Commit

Permalink
Refactor jumpstart into a Django app.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Jun 12, 2012
1 parent e095e04 commit 8d5cc34
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 26 deletions.
10 changes: 10 additions & 0 deletions 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()

Empty file added config/jumpstart/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions 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'
)

10 changes: 10 additions & 0 deletions 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')
)

34 changes: 9 additions & 25 deletions jumpstart/application.py → jumpstart/views.py
Expand Up @@ -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
Expand All @@ -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)

4 changes: 3 additions & 1 deletion 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.