Updated ubuntu and adapted debian install scripts for Wagtail production configuration instance on a fresh box. Accompanying uwsgi init.d script for debian. npm/less to be removed and init.d script location to be updated.

pull/137/head
Neal Todd 2014-03-05 13:58:39 +00:00
rodzic 5ef4f0b07a
commit a19459e1b2
3 zmienionych plików z 257 dodań i 8 usunięć

Wyświetl plik

@ -0,0 +1,129 @@
# Production-configured Wagtail installation
# (secure services/account for full production use).
# Tested on Debian 7.0.
# Tom Dyson and Neal Todd
# NB: Ensure the system locale is okay before running (dpkg-reconfigure locales).
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
[$CONFIRM== “yes” ] || exit
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
echo -e "\nPlease come back in a few minutes, when we'll need you to create an admin account."
sleep 5
SERVER_IP=`ifconfig eth0 |grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
aptitude update
aptitude -y install git python-pip nginx postgresql redis-server
aptitude -y install postgresql-server-dev-all python-dev libxml2-dev libxslt-dev libjpeg62-dev
wget -nv http://nodejs.org/dist/v0.10.20/node-v0.10.20.tar.gz
tar xzf node-v0.10.20.tar.gz
cd node-v0.10.20
./configure && make -s && make -s install
cd ..
rm -r node-v0.10.20 node-v0.10.20.tar.gz
npm install -g less
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
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.0.deb
dpkg -i elasticsearch-1.0.0.deb
rm elasticsearch-1.0.0.deb
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
echo SECRET_KEY = \"`python -c 'import random; print "".join([random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'`\" > $PROJECT/settings.local.py
echo ALLOWED_HOSTS = [\'$SERVER_IP\',] >> $PROJECT/settings/local.py
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 {
alias $PROJECT_ROOT/$PROJECT/media;
}
location /static {
alias $PROJECT_ROOT/$PROJECT/static;
}
location / {
uwsgi_pass django;
include $PROJECT_ROOT/$PROJECT/uwsgi_params;
}
}
EOF
cat << EOF > $PROJECT_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/
curl -o /etc/init.d/uwsgi https://gist.githubusercontent.com/nealtodd/9364691/raw/43f0bdb1304995ab73e3d22e62e14111d40d4e90/uwsgi-init.d
mkdir /var/log/uwsgi
chmod 755 /etc/init.d/uwsgi
update-rc.d uwsgi defaults
service uwsgi start
service nginx restart
URL="http://$SERVER_IP"
echo -e "\n\nWagtail lives!\n\n"
echo "The public site is at $URL/"
echo "and the admin interface is at $URL/admin/"

Wyświetl plik

@ -1,4 +1,6 @@
# Production-ready Wagtail installation, tested on Ubuntu 13.10
# Production-configured Wagtail installation
# (secure services/account for full production use).
# Tested on Ubuntu 13.10.
# Tom Dyson and Neal Todd
PROJECT=mywagtail
@ -22,9 +24,12 @@ if [ ! -z "$PROJECT_ROOT" ]; then
mkdir -p $PROJECT_ROOT || exit
fi
echo "Please come back in a few minutes, when we'll need you to create an admin account."
echo -e "\nPlease come back in a few minutes, when we'll need you to create an admin account."
sleep 5
SERVER_IP=`ifconfig eth0 |grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
aptitude update
aptitude -y install git python-pip nginx postgresql redis-server
aptitude -y install postgresql-server-dev-all python-dev libxml2-dev libxslt-dev libjpeg62-dev
@ -36,7 +41,7 @@ perl -pi -e "s/^(local\s+all\s+postgres\s+)peer$/\1trust/" /etc/postgresql/9.1/m
service postgresql reload
aptitude -y install openjdk-7-jre-headless
curl -o elasticsearch-1.0.0.deb https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.0.deb
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.0.deb
dpkg -i elasticsearch-1.0.0.deb
rm elasticsearch-1.0.0.deb
update-rc.d elasticsearch defaults 95 10
@ -57,7 +62,7 @@ swapoff -v /tmpswap
rm /tmpswap
echo SECRET_KEY = \"`python -c 'import random; print "".join([random.SystemRandom().choice("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)") for i in range(50)])'`\" > $PROJECT/settings.local.py
echo ALLOWED_HOSTS = [\'`ifconfig eth0 |grep "inet addr" | cut -d: -f2 | cut -d" " -f1`\',] >> $PROJECT/settings/local.py
echo ALLOWED_HOSTS = [\'$SERVER_IP\',] >> $PROJECT/settings/local.py
createdb -Upostgres $PROJECT
./manage.py syncdb --settings=$PROJECT.settings.production
./manage.py migrate --settings=$PROJECT.settings.production
@ -78,13 +83,15 @@ server {
charset utf-8;
client_max_body_size 75M; # max upload size
location /media {
alias $PROJECT_ROOT/$PROJECT/media; }
alias $PROJECT_ROOT/$PROJECT/media;
}
location /static {
alias $PROJECT_ROOT/$PROJECT/static;
}
location / {
uwsgi_pass django;
include $PROJECT_ROOT/$PROJECT/uwsgi_params; }
include $PROJECT_ROOT/$PROJECT/uwsgi_params;
}
}
EOF
@ -112,7 +119,7 @@ EOF
service uwsgi start
service nginx restart
URL="http://`ifconfig eth0 |grep "inet addr" | cut -d: -f2 | cut -d" " -f1`"
echo "Wagtail lives!"
URL="http://$SERVER_IP"
echo -e "\n\nWagtail lives!\n\n"
echo "The public site is at $URL/"
echo "and the admin interface is at $URL/admin/"

Wyświetl plik

@ -0,0 +1,113 @@
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: emperor
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: uwsgi for wagtail
# Description: uwsgi for wagtail
### END INIT INFO
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DAEMON=/usr/local/bin/uwsgi
RUN=/var/run/uwsgi
CONFIG_DIR=/etc/uwsgi/vassals
NAME=uwsgi
DESC=emperor
OWNER=root
GROUP=root
OP=$1
[[ -x $DAEMON ]] || exit 0
[[ -d $RUN ]] || mkdir $RUN && chown $OWNER.$GROUP $RUN
do_pid_check()
{
local PIDFILE=$1
[[ -f $PIDFILE ]] || return 0
local PID=$(cat $PIDFILE)
for p in $(pgrep $NAME); do
[[ $p == $PID ]] && return 1
done
return 0
}
do_start()
{
local PIDFILE=$RUN/$NAME.pid
local START_OPTS=" \
--emperor $CONFIG_DIR \
--pidfile $PIDFILE \
--uid $OWNER --gid $GROUP \
--daemonize /var/log/$NAME/uwsgi-emperor.log"
if do_pid_check $PIDFILE; then
$NAME $START_OPTS
else
echo "Already running!"
fi
}
send_sig()
{
local PIDFILE=$RUN/$NAME.pid
set +e
[[ -f $PIDFILE ]] && kill $1 $(cat $PIDFILE) > /dev/null 2>&1
set -e
}
wait_and_clean_pidfile()
{
local PIDFILE=$RUN/uwsgi.pid
until do_pid_check $PIDFILE; do
echo -n "";
done
rm -f $PIDFILE
}
do_stop()
{
send_sig -3
wait_and_clean_pidfile
}
do_reload()
{
send_sig -1
}
case "$OP" in
start)
echo "Starting $DESC: "
do_start
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
do_stop
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC: "
do_reload
echo "$NAME."
;;
restart)
echo "Restarting $DESC: "
do_stop
sleep 1
do_start
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload}">&2
exit 1
;;
esac
exit 0