Skip to content

Commit

Permalink
switch deployment from dotcloud to our own server
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshData authored and ancbrigade committed Mar 5, 2014
1 parent 277a16f commit 03b5fd7
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 63 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you're using a virtual environment, set that up:
Then, install dependencies and set up the site database:

sudo apt-get install libxslt1-dev # Not necessary on OSX
sudo pip install -r requirements.txt
pip install -r requirements.txt
./manage.py syncdb

If it seems like you're missing stuff, also try
Expand Down Expand Up @@ -90,10 +90,8 @@ All of the scripts should be run occasionally to make sure the data shown on the
Deployment
----------

We're currently deploying to dotCloud.
When deploying the code to the live server, remember to update the static files:

./manage.py collectstatic

sudo pip install dotcloud
dotcloud setup
dotcloud connect ancbrigade
dotcloud push # push changes to the live site

41 changes: 22 additions & 19 deletions ancbrigadesite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@

import os.path

DEBUG = True
TEMPLATE_DEBUG = DEBUG

RECAPTCHA_PUBLIC_KEY = '6LeYAO8SAAAAALEZqtnk4qm7hoh8Iwv_h4lZ3lSe'
RECAPTCHA_PRIVATE_KEY = '6LeYAO8SAAAAAICslEpPIpmMmkFiuNs_hrAzSRxx'

if not os.path.exists('/home/dotcloud/environment.json'):
environment_file = '/home/ancbrigade/environment.json'

if not os.path.exists(environment_file):
# Settings for local (not public) deployments.

# Make this unique, and don't share it with anybody.

print "Running a local deployment..."

DEBUG = True
TEMPLATE_DEBUG = DEBUG

# For a simple setup when debugging, we'll hard-code these values.
SECRET_KEY = '7^^6oohvb%oc3$&4z^#vplkp(!@dy24nm$d6a2g9^w#imqpme8'

DATABASES = {
Expand All @@ -39,32 +43,31 @@

DEBUG = False
TEMPLATE_DEBUG = False
import json
with open('/home/dotcloud/environment.json') as f:
env = json.load(f)

import yaml
with open(environment_file) as f:
env = yaml.load(f)
SECRET_KEY = env['DJANGO_SECRET_KEY']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'template1',
'USER': env['DOTCLOUD_DB_SQL_LOGIN'],
'PASSWORD': env['DOTCLOUD_DB_SQL_PASSWORD'],
'HOST': env['DOTCLOUD_DB_SQL_HOST'],
'PORT': int(env['DOTCLOUD_DB_SQL_PORT']),
'HOST': env['DATABASE_HOST'],
'PORT': int(env['DATABASE_PORT']),
'NAME': env['DATABASE_NAME'],
'USER': env['DATABASE_USERNAME'],
'PASSWORD': env['DATABASE_PASSWORD'],
}
}

ADMINS = (
(env['DOTCLOUD_USERNAME'], env['DOTCLOUD_EMAIL']),
)
ADMINS = env['ADMINS']
MANAGERS = ADMINS

EMAIL_HOST = env['SMTP_HOST']
EMAIL_HOST_USER = env['SMTP_USER']
EMAIL_HOST_PASSWORD = env['SMTP_PASSWORD']
EMAIL_USE_TLS = True

ALLOWED_HOSTS = ["www.ancbrigade.com", "www.ancfinder.com", "www.ancbrigade.net", "www.ancbrigade.org", "www.ancfinder.org"]
ALLOWED_HOSTS = ["*"] # anything unexpected will be filtered out by the http server

# Local time zone for this installation. Choices can be found here:
# http:https://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand Down Expand Up @@ -102,7 +105,7 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/home/dotcloud/volatile/static/'
STATIC_ROOT = '/home/ancbrigade/volatile/static/'

# URL prefix for static files.
# Example: "http:https://media.lawrence.com/static/"
Expand Down
4 changes: 2 additions & 2 deletions conf/crontab
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MAILTO=[email protected]
14 3 * * * { cd /home/dotcloud/current; ../env/bin/python update_meeting_times.py; }
MAILTO=tauberer+anc@govtrack.us
14 3 * * * { cd /home/ancbrigade/web; .env/bin/python update_meeting_times.py; }
52 changes: 52 additions & 0 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Please edit with extreme caution. --JT

# redirect non-canonical domains
server {
listen 80;
listen [::]:80;
server_name ancbrigade.com;
server_name www.ancbrigade.com;
server_name ancbrigade.net;
server_name www.ancbrigade.net;
server_name ancbrigade.org;
server_name www.ancbrigade.org;
server_name ancfinder.com;
server_name www.ancfinder.com;
server_name www.ancfinder.org;
rewrite /(.*) http:https://ancfinder.org/$1 permanent;
}

# the canonical domain
server {
listen 80;

server_name ancfinder.org;
access_log /home/ancbrigade/logs/www_access_log;

root /home/ancbrigade/web/static/root;

error_page 503 @maintenance;
location @maintenance {
rewrite (.*) /static/maintenance.html last;
}

location / {
#return 503; # maintenance mode activated

include fastcgi_params;
fastcgi_split_path_info ^()(.*)$;
fastcgi_pass localhost:3010;
fastcgi_read_timeout 20s;
}

location /static/ {
alias /home/ancbrigade/volatile/static/;
expires 7d;
}

location ~ ^/(robots.txt|favicon.ico)$ {
root /home/ancbrigade/volatile/static;
expires 3d;
}
}

8 changes: 0 additions & 8 deletions dotcloud.yml

This file was deleted.

3 changes: 0 additions & 3 deletions dotcloud_set_secret_key.sh

This file was deleted.

129 changes: 129 additions & 0 deletions fcgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash

# Start, stop, restart, or graceful restart the FastCGI server.
# With no arguments, stops any executing instance and then
# starts a new one. With the argument 'stop', stops all executing
# instances but does not start a new one. With the argument
# 'graceful', a new instance is started on a fresh port and once
# it is started the old instances are killed for a graceful
# restart, using SIGHUP to gracefully end FastCGI.

# change to the site directory, where this script is located
ME=`readlink -m $0`
MYDIR=`dirname $ME`
cd $MYDIR

if [ "$USER" = "" ]; then
echo "USER environment variable not set.";
exit;
fi

# Load settings.
PORT=`echo 1000+$UID*2|bc`
if [ -f fcgi.conf ]; then
. fcgi.conf
fi
if [ "$NAME" = "" ]; then NAME=$PORT; fi
if [ "$INSTANCES" = "" ]; then INSTANCES=6; fi
if [ "$INSTANCES_MIN" = "" ]; then INSTANCES_MIN=$INSTANCES; fi
if [ "$INSTANCES_MAX" = "" ]; then INSTANCES_MAX=$INSTANCES; fi
if [ "$INSTANCE_MAX_REQUESTS" = "" ]; then INSTANCE_MAX_REQUESTS=1000; fi

if [ "$1" = "" ]; then
# Hard restart: Do a stop first. The rest of this script
# will start a new instance on the default port.
./fcgi stop
fi

HOSTNAME=`hostname -I | tr -d ' '` # assumes only one interface
HOSTNAME=127.0.0.1

# Get the CURPID, CURPIDFILE, and CURPORT of the running instance.
for CURPIDFILE in `ls /tmp | egrep "django-fcgi-$NAME-$PORT.pid"`
do
CURPID=`cat -- /tmp/$CURPIDFILE`;
CURPORT=`echo $CURPIDFILE | sed "s/.*-\([0-9]*\).pid/\1/"`;

# Stop: Kill the running instance (exit after killing all
# running instances).
if [ "$1" = "stop" ]; then
echo "Stopping $CURPORT (pid=$CURPID)...";
kill -HUP $CURPID;

# Wait for the port to clear.
CTR=0
while [ "`netstat -tln |grep $CURPORT`" != "" ]; do
if [ $CTR -gt 1 ]; then
echo "Port $CURPORT still bound...";
netstat -tln |grep $CURPORT;
fi
if [ $CTR -gt 10 ]; then
echo "Killing $CURPORT (pid=$CURPID)...";
kill $CURPID;
break;
fi
CTR=`echo $CTR+1|bc`
sleep 1;
done

rm -f -- /tmp/$CURPIDFILE;
fi
done

# Stop: Kill the running instance and exit.
if [ "$1" = "stop" ]; then
exit;
fi

# If it is the same as the running instance's port in a
# graceful restart, add 1.
if [ "$PORT" = "$CURPORT" ]; then
PORT=`echo $PORT+1|bc`
fi

# Start the new instance...

# Wait for the port to clear.
CTR=0
while [ "`netstat -tln |grep $PORT`" != "" ]; do
if [ $CTR -gt 1 ]; then
echo "Port $PORT already bound...";
netstat -tln |grep $PORT;
fi
CTR=`echo $CTR+1|bc`
sleep 1;
done

echo "Starting $NAME $HOSTNAME:$PORT x $INSTANCES...";

# select a PIDFILE
PIDFILE=/tmp/django-fcgi-$NAME-$PORT.pid

export NAME=$NAME
PYTHONPATH=.. ./manage.py runfcgi host=$HOSTNAME port=$PORT pidfile=$PIDFILE \
workdir=$MYDIR umask=0002 debug=1 \
maxchildren=$INSTANCES_MAX minspare=$INSTANCES_MIN maxspare=$INSTANCES_MAX \
maxrequests=$INSTANCE_MAX_REQUESTS \
timeout=25 \
outlog=~/logs/django_output_log errlog=~/logs/django_error_log ;

# Kill the previously running instance.
if [ "$CURPIDFILE" != "" ]; then
sleep 2; # give the new instance a chance to start up and
# the old instance a chance to complete requests

echo "Stopping $CURPIDFILE (port=$CURPORT, pid=$CURPID)...";
kill -HUP $CURPID;
rm -f -- /tmp/$CURPIDFILE;

# wait for the port to clear
CTR=0
while [ "`netstat -tln |grep $CURPORT`" != "" ]; do
if [ $CTR -gt 1 ]; then
echo "Waiting for port $CURPORT to be freed...";
netstat -tln |grep $PORT;
fi
CTR=`echo $CTR+1|bc`
sleep 1;
done
fi
5 changes: 5 additions & 0 deletions fcgi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PORT=3010
NAME=ancbrigade
INSTANCES_MIN=3
INSTANCES_MAX=16
INSTANCE_MAX_REQUESTS=200
3 changes: 0 additions & 3 deletions nginx.conf

This file was deleted.

5 changes: 0 additions & 5 deletions postinstall

This file was deleted.

10 changes: 0 additions & 10 deletions postinstall.py

This file was deleted.

2 changes: 1 addition & 1 deletion update_meeting_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def mkdir_p(path):
room = room.find('div','field-item').text
except AttributeError:
room = None
print link
#print link # any output gets emailed to Josh whenever this script is run by cron, so let's not have output
details = {'address':address,'building':building,'room':room,'link':link}
try:
archive[anc]['meetings'][date] = details
Expand Down
6 changes: 0 additions & 6 deletions wsgi.py

This file was deleted.

0 comments on commit 03b5fd7

Please sign in to comment.