2014-07-16 12:04:34 +00:00
#!/usr/bin/env bash
2014-05-21 16:49:04 +00:00
# Production-configured Wagtail installation.
# BUT, SECURE SERVICES/ACCOUNT FOR FULL PRODUCTION USE!
2014-05-27 15:54:06 +00:00
# For a non-dummy email backend configure Django's EMAIL_BACKEND
# in settings/production.py post-installation.
2014-03-06 15:50:05 +00:00
# Tested on Ubuntu 13.04 and 13.10.
2014-03-04 17:10:04 +00:00
# Tom Dyson and Neal Todd
PROJECT = mywagtail
PROJECT_ROOT = /usr/local/django
echo "This script overwrites key files, and should only be run on a new box."
read -p "Type 'yes' to confirm: " CONFIRM
2014-07-16 12:04:34 +00:00
[ " $CONFIRM " = = "yes" ] || exit
2014-03-04 17:10:04 +00:00
read -p " Enter a name for your project [ $PROJECT ]: " U_PROJECT
if [ ! -z " $U_PROJECT " ] ; then
PROJECT = $U_PROJECT
fi
read -p " Enter the root of your project, without trailing slash [ $PROJECT_ROOT ]: " U_PROJECT_ROOT
if [ ! -z " $U_PROJECT_ROOT " ] ; then
PROJECT_ROOT = $U_PROJECT_ROOT
fi
if [ ! -z " $PROJECT_ROOT " ] ; then
mkdir -p $PROJECT_ROOT || exit
fi
2014-03-05 13:58:39 +00:00
echo -e "\nPlease come back in a few minutes, when we'll need you to create an admin account."
2014-03-04 17:10:04 +00:00
sleep 5
2014-03-05 13:58:39 +00:00
SERVER_IP = ` ifconfig eth0 | grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
aptitude update
2014-03-04 17:10:04 +00:00
aptitude -y install git python-pip nginx postgresql redis-server
2014-07-17 12:43:14 +00:00
aptitude -y install postgresql-server-dev-all python-dev libjpeg62-dev
2014-03-04 17:10:04 +00:00
perl -pi -e " s/^(local\s+all\s+postgres\s+)peer $/\1trust/ " /etc/postgresql/9.1/main/pg_hba.conf
service postgresql reload
aptitude -y install openjdk-7-jre-headless
2014-03-05 13:58:39 +00:00
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.0.deb
2014-03-04 17:10:04 +00:00
dpkg -i elasticsearch-1.0.0.deb
rm elasticsearch-1.0.0.deb
2014-05-21 16:49:04 +00:00
perl -pi -e"s/# network.host: 192.168.0.1/network.host: 127.0.0.1/" /etc/elasticsearch/elasticsearch.yml
2014-03-04 17:10:04 +00:00
update-rc.d elasticsearch defaults 95 10
service elasticsearch start
cd $PROJECT_ROOT
git clone https://github.com/torchbox/wagtaildemo.git $PROJECT
cd $PROJECT
mv wagtaildemo $PROJECT
perl -pi -e" s/wagtaildemo/ $PROJECT / " manage.py $PROJECT /wsgi.py $PROJECT /settings/*.py
rm -r etc README.md Vagrantfile* .git .gitignore
dd if = /dev/zero of = /tmpswap bs = 1024 count = 524288
mkswap /tmpswap
swapon /tmpswap
pip install -r requirements/production.txt
swapoff -v /tmpswap
rm /tmpswap
2014-07-15 08:10:29 +00:00
echo SECRET_KEY = \" ` python -c 'import random; print "".join([random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])' ` \" > $PROJECT /settings/local.py
2014-03-05 13:58:39 +00:00
echo ALLOWED_HOSTS = [ \' $SERVER_IP \' ,] >> $PROJECT /settings/local.py
2014-03-04 17:10:04 +00:00
createdb -Upostgres $PROJECT
./manage.py syncdb --settings= $PROJECT .settings.production
./manage.py migrate --settings= $PROJECT .settings.production
./manage.py update_index --settings= $PROJECT .settings.production
./manage.py collectstatic --settings= $PROJECT .settings.production --noinput
pip install uwsgi
cp $PROJECT /wsgi.py $PROJECT /wsgi_production.py
perl -pi -e" s/( $PROJECT .settings)/\1.production/ " $PROJECT /wsgi_production.py
curl -O https://raw2.github.com/nginx/nginx/master/conf/uwsgi_params
cat << EOF > /etc/nginx/sites-enabled/default
upstream django {
server unix://$PROJECT_ROOT /$PROJECT /uwsgi.sock;
}
server {
listen 80;
charset utf-8;
client_max_body_size 75M; # max upload size
location /media {
2014-03-05 13:58:39 +00:00
alias $PROJECT_ROOT /$PROJECT /media;
}
2014-03-04 17:10:04 +00:00
location /static {
alias $PROJECT_ROOT /$PROJECT /static;
}
location / {
uwsgi_pass django;
2014-03-05 13:58:39 +00:00
include $PROJECT_ROOT /$PROJECT /uwsgi_params;
}
2014-03-04 17:10:04 +00:00
}
EOF
cat << EOF > $PROJE CT_ROOT/$PROJECT /uwsgi_conf.ini
[ uwsgi]
chdir = $PROJECT_ROOT /$PROJECT
module = $PROJECT .wsgi_production
master = true
processes = 10
socket = $PROJECT_ROOT /$PROJECT /uwsgi.sock
chmod-socket = 666
vacuum = true
EOF
mkdir -p /etc/uwsgi/vassals/
ln -s $PROJECT_ROOT /$PROJECT /uwsgi_conf.ini /etc/uwsgi/vassals/
cat << EOF > /etc/init/uwsgi.conf
description "uwsgi for wagtail"
start on runlevel [ 2345]
stop on runlevel [ 06]
exec uwsgi --emperor /etc/uwsgi/vassals
EOF
service uwsgi start
service nginx restart
2014-03-05 13:58:39 +00:00
URL = " http:// $SERVER_IP "
echo -e "\n\nWagtail lives!\n\n"
2014-03-04 17:10:04 +00:00
echo " The public site is at $URL / "
echo " and the admin interface is at $URL /admin/ "