Changes between Version 3 and Version 4 of InstallationGuidelines/Linux/Server/CherokeePostgreSQL


Ignore:
Timestamp:
10/22/11 07:48:18 (10 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • InstallationGuidelines/Linux/Server/CherokeePostgreSQL

    v3 v4  
     1[[TOC]]
    12= Installation Guidelines: Linux (Production: Cherokee/PostgreSQL) =
    23Installs that we maintain are usually done using Cherokee & PostgreSQL
     
    45 * [wiki:InstallationGuidelinesCherokee Cherokee] is a high-performance web server with a graphical admin UI
    56 * [wiki:InstallationGuidelinesPostgreSQL PostgreSQL] is a database with powerful geospatial support
     7
     8The simplest way to install is using our attached installation scripts.
     9
     10This is split into 2 halves, as the 1st script can create a base image which is then customised per-instance using the configure script.
     11
     12Note: We install using the latest Trunk versions of both Web2Py & Eden. This can occasionally cause problems.
     13
     14== Before Imaging ==
     15[http://eden.sahanafoundation.org/raw-attachment/wiki/InstallationGuidelines/Linux/Server/CherokeePostgreSQL/install-eden-cherokee-postgis.sh install-eden-cherokee-postgis.sh]
     16{{{
     17#!/bin/sh
     18
     19# Script to turn a generic Debian Squeeze box into an Eden server
     20# with Cherokee & PostgreSQL
     21# - tunes PostgreSQL for 1Gb RAM
     22
     23# Update system
     24apt-get update
     25apt-get upgrade -y
     26
     27# Install Admin Tools
     28apt-get install -y unzip psmisc mlocate telnet lrzsz vim elinks-lite rcconf htop sudo
     29# Email
     30apt-get -y install exim4-config exim4-daemon-light
     31
     32#########
     33# Python
     34#########
     35# Install Libraries
     36apt-get -y install libgeos-c1
     37
     38# Install Python 2.6
     39apt-get -y install python2.6 python-dev ipython
     40apt-get -y install python-lxml python-setuptools python-shapely python-dateutil
     41apt-get -y install python-serial
     42apt-get -y install python-imaging python-reportlab
     43apt-get -y install python-xlwt python-xlrd
     44apt-get -y install bzr
     45
     46#########
     47# Web2Py
     48#########
     49# Install Web2Py
     50adduser --system --disabled-password web2py
     51addgroup web2py
     52cd /home
     53bzr branch lp:~mdipierro/web2py/devel web2py --use-existing-dir
     54ln -s /home/web2py ~
     55cat << EOF > "/home/web2py/routes.py"
     56#!/usr/bin/python
     57default_application = 'eden'
     58default_controller = 'default'
     59default_function = 'index'
     60routes_onerror = [
     61        ('eden/400', '!'),
     62        ('eden/401', '!'),
     63        ('eden/*', '/eden/errors/index'),
     64        ('*/*', '/eden/errors/index'),
     65    ]
     66EOF
     67
     68
     69##############
     70# Sahana Eden
     71##############
     72# Install Sahana Eden
     73cd web2py
     74cd applications
     75bzr branch lp:sahana-eden eden
     76# Fix permissions
     77chown web2py ~web2py
     78chown web2py ~web2py/applications/admin/cache
     79chown web2py ~web2py/applications/admin/cron
     80chown web2py ~web2py/applications/admin/databases
     81chown web2py ~web2py/applications/admin/errors
     82chown web2py ~web2py/applications/admin/sessions
     83chown web2py ~web2py/applications/eden
     84chown web2py ~web2py/applications/eden/cache
     85chown web2py ~web2py/applications/eden/cron
     86chown web2py ~web2py/applications/eden/databases
     87chown web2py ~web2py/applications/eden/errors
     88chown web2py ~web2py/applications/eden/models
     89chown web2py ~web2py/applications/eden/sessions
     90chown web2py ~web2py/applications/eden/static/img/markers
     91chown web2py ~web2py/applications/eden/uploads
     92mkdir -p ~web2py/applications/eden/uploads/gis_cache
     93mkdir -p ~web2py/applications/eden/uploads/images
     94mkdir -p ~web2py/applications/eden/uploads/tracks
     95chown web2py ~web2py/applications/eden/uploads/gis_cache
     96chown web2py ~web2py/applications/eden/uploads/images
     97chown web2py ~web2py/applications/eden/uploads/tracks
     98ln -s /home/web2py/applications/eden ~
     99
     100##########
     101# Cherokee
     102##########
     103# Debian current version
     104#apt-get -y install libcherokee-mod-libssl libcherokee-mod-rrd
     105# Source version
     106CHEROKEE_CONF="/usr/local/etc/cherokee/cherokee.conf"
     107apt-get install -y gettext libgeoip-dev libssl-dev rrdtool make
     108cd /tmp
     109wget http://www.cherokee-project.com/download/1.2/1.2.99/cherokee-1.2.99.tar.gz
     110tar zxvf cherokee-1.2.99.tar.gz
     111cd cherokee-1.2.99
     112./configure --datarootdir=/var/www
     113make
     114make install
     115mkdir /var/log/cherokee
     116chown www-data /var/log/cherokee
     117wget http://eden.sahanafoundation.org/raw-attachment/wiki/InstallationGuidelinesCherokee/cherokee -O /etc/init.d/cherokee
     118chmod +x /etc/init.d/cherokee
     119ldconfig
     120rcconf --on cherokee
     121
     122# Install uWSGI
     123apt-get install -y libxml2-dev
     124cd /tmp
     125wget http://projects.unbit.it/downloads/uwsgi-0.9.9.2.tar.gz
     126tar zxvf uwsgi-0.9.9.2.tar.gz
     127cd uwsgi-0.9.9.2
     128make
     129cp uwsgi /usr/local/bin
     130cd ..
     131
     132# Configure Cherokee
     133cat << EOF > "/home/web2py/uwsgi.xml"
     134<uwsgi>
     135    <pythonpath>/home/web2py/</pythonpath>
     136    <app mountpoint="/">
     137        <script>wsgihandler</script>
     138    </app>
     139    <workers>4</workers>
     140</uwsgi>
     141EOF
     142
     143mv "$CHEROKEE_CONF" /tmp
     144cat << EOF > "$CHEROKEE_CONF"
     145config!version = 001002002
     146server!bind!1!port = 80
     147server!collector = rrd
     148server!fdlimit = 10240
     149server!group = www-data
     150server!ipv6 = 0
     151server!keepalive = 1
     152server!keepalive_max_requests = 500
     153server!panic_action = /usr/share/cherokee/cherokee-panic
     154server!pid_file = /var/run/cherokee.pid
     155server!server_tokens = product
     156server!timeout = 300
     157server!user = www-data
     158vserver!10!collector!enabled = 1
     159vserver!10!directory_index = index.html
     160vserver!10!document_root = /var/www
     161vserver!10!error_writer!filename = /var/log/cherokee/cherokee.error
     162vserver!10!error_writer!type = file
     163vserver!10!logger = combined
     164vserver!10!logger!access!buffsize = 16384
     165vserver!10!logger!access!filename = /var/log/cherokee/cherokee.access
     166vserver!10!logger!access!type = file
     167vserver!10!nick = default
     168vserver!10!rule!10!handler = common
     169vserver!10!rule!10!handler!iocache = 1
     170vserver!10!rule!10!match = default
     171vserver!20!collector!enabled = 1
     172vserver!20!directory_index = index.html
     173vserver!20!document_root = /var/www
     174vserver!20!error_writer!filename = /var/log/cherokee/cherokee.error
     175vserver!20!error_writer!type = file
     176vserver!20!logger = combined
     177vserver!20!logger!access!buffsize = 16384
     178vserver!20!logger!access!filename = /var/log/cherokee/cherokee.access
     179vserver!20!logger!access!type = file
     180vserver!20!match = wildcard
     181vserver!20!match!domain!1 = *
     182vserver!20!match!nick = 0
     183vserver!20!nick = maintenance
     184vserver!20!rule!210!handler = file
     185vserver!20!rule!210!match = fullpath
     186vserver!20!rule!210!match!fullpath!1 = /maintenance.html
     187vserver!20!rule!110!handler = redir
     188vserver!20!rule!110!handler!rewrite!10!regex = ^/*
     189vserver!20!rule!110!handler!rewrite!10!show = 1
     190vserver!20!rule!110!handler!rewrite!10!substring = /maintenance.html
     191vserver!20!rule!110!match = directory
     192vserver!20!rule!110!match!directory = /
     193vserver!20!rule!10!handler = common
     194vserver!20!rule!10!handler!iocache = 1
     195vserver!20!rule!10!match = default
     196vserver!30!collector!enabled = 1
     197vserver!30!directory_index = index.html
     198vserver!30!document_root = /var/www
     199vserver!30!error_writer!filename = /var/log/cherokee/cherokee.error
     200vserver!30!error_writer!type = file
     201vserver!30!logger = combined
     202vserver!30!logger!access!buffsize = 16384
     203vserver!30!logger!access!filename = /var/log/cherokee/cherokee.access
     204vserver!30!logger!access!type = file
     205vserver!30!match = wildcard
     206vserver!30!match!domain!1 = *
     207vserver!30!match!nick = 0
     208vserver!30!nick = Production
     209vserver!30!rule!400!document_root = /home/web2py/applications/eden/static
     210vserver!30!rule!400!encoder!deflate = allow
     211vserver!30!rule!400!encoder!gzip = allow
     212vserver!30!rule!400!expiration = time
     213vserver!30!rule!400!expiration!time = 7d
     214vserver!30!rule!400!handler = file
     215vserver!30!rule!400!match = fullpath
     216vserver!30!rule!400!match!fullpath!1 = /favicon.ico
     217vserver!30!rule!400!match!fullpath!2 = /robots.txt
     218vserver!30!rule!400!match!fullpath!3 = /crossdomain.xml
     219vserver!30!rule!300!document_root = /home/web2py/applications/eden/static
     220vserver!30!rule!300!encoder!deflate = allow
     221vserver!30!rule!300!encoder!gzip = allow
     222vserver!30!rule!300!expiration = time
     223vserver!30!rule!300!expiration!time = 7d
     224vserver!30!rule!300!handler = file
     225vserver!30!rule!300!match = directory
     226vserver!30!rule!300!match!directory = /eden/static/
     227vserver!30!rule!300!match!final = 1
     228vserver!30!rule!200!encoder!deflate = allow
     229vserver!30!rule!200!encoder!gzip = allow
     230vserver!30!rule!200!handler = uwsgi
     231vserver!30!rule!200!handler!balancer = round_robin
     232vserver!30!rule!200!handler!balancer!source!10 = 1
     233vserver!30!rule!200!handler!check_file = 0
     234vserver!30!rule!200!handler!error_handler = 1
     235vserver!30!rule!200!handler!modifier1 = 0
     236vserver!30!rule!200!handler!modifier2 = 0
     237vserver!30!rule!200!handler!pass_req_headers = 1
     238vserver!30!rule!200!match = directory
     239vserver!30!rule!200!match!directory = /
     240vserver!30!rule!100!handler = common
     241vserver!30!rule!100!handler!iocache = 1
     242vserver!30!rule!100!match = default
     243source!1!env_inherited = 1
     244source!1!group = web2py
     245source!1!host = 127.0.0.1:59025
     246source!1!interpreter = /usr/local/bin/uwsgi -s 127.0.0.1:59025 -x /home/web2py/uwsgi.xml
     247source!1!nick = uWSGI 1
     248source!1!timeout = 300
     249source!1!type = interpreter
     250source!1!user = web2py
     251EOF
     252
     253grep 'icons!' /tmp/cherokee.conf >> "$CHEROKEE_CONF"
     254grep 'mime!' /tmp/cherokee.conf >> "$CHEROKEE_CONF"
     255
     256cat << EOF >> "$CHEROKEE_CONF"
     257admin!ows!enabled = 0
     258EOF
     259
     260# For a static home page, push 400->500 & 300->400 & insert this
     261#vserver!30!rule!300!document_root = /home/web2py/applications/eden/static
     262#vserver!30!rule!300!handler = redir
     263#vserver!30!rule!300!handler!rewrite!10!regex = ^.*$
     264#vserver!30!rule!300!handler!rewrite!10!show = 1
     265#vserver!30!rule!300!handler!rewrite!10!substring = /eden/static/index.html
     266#vserver!30!rule!300!match = and
     267#vserver!30!rule!300!match!final = 1
     268#vserver!30!rule!300!match!left = fullpath
     269#vserver!30!rule!300!match!left!fullpath!1 = /
     270#vserver!30!rule!300!match!right = not
     271#vserver!30!rule!300!match!right!right = header
     272#vserver!30!rule!300!match!right!right!complete = 0
     273#vserver!30!rule!300!match!right!right!header = Cookie
     274#vserver!30!rule!300!match!right!right!match = re
     275#vserver!30!rule!300!match!right!right!type = regex
     276
     277
     278cat << EOF > "/var/www/maintenance.html"
     279<html><body><h1>Site Maintenance</h1>Please try again later...</body></html>
     280EOF
     281
     282chown -R www-data /usr/local/var/lib/cherokee
     283/etc/init.d/cherokee restart
     284
     285# Logfile rotation
     286cat << EOF > "/etc/logrotate.d/cherokee"
     287/var/log/cherokee/*.error /var/log/cherokee/*.access /var/log/cherokee.access /var/log/cherokee.error {
     288  rotate 7
     289  weekly
     290  compress
     291  copytruncate
     292  missingok
     293  notifempty
     294  copytruncate
     295}
     296EOF
     297
     298############
     299# PostgreSQL
     300############
     301apt-get -y install postgresql-8.4 python-psycopg2 postgresql-8.4-postgis ptop
     302
     303# Tune PostgreSQL
     304cat << EOF >> "/etc/sysctl.conf"
     305## Increase Shared Memory available for PostgreSQL
     306# 512Mb
     307#kernel.shmmax = 279134208
     308# 1024Mb (may need more)
     309kernel.shmmax = 552992768
     310kernel.shmall = 2097152
     311EOF
     312sysctl -w kernel.shmmax=552992768
     313sysctl -w kernel.shmall=2097152
     314
     315sed -i 's|#track_counts = on|track_counts = on|' /etc/postgresql/8.4/main/postgresql.conf
     316sed -i 's|#autovacuum = on|autovacuum = on|' /etc/postgresql/8.4/main/postgresql.conf
     317sed -i 's|shared_buffers = 28MB|shared_buffers = 160MB|' /etc/postgresql/8.4/main/postgresql.conf
     318sed -i 's|#effective_cache_size = 128MB|effective_cache_size = 512MB|' /etc/postgresql/8.4/main/postgresql.conf
     319sed -i 's|#work_mem = 1MB|work_mem = 4MB|' /etc/postgresql/8.4/main/postgresql.conf
     320
     321#####################
     322# Management scripts
     323#####################
     324cat << EOF > "/usr/local/bin/backup"
     325#!/bin/sh
     326NOW=$(date +"%Y-%m-%d")
     327su postgres
     328pg_dump -c sahana > /root/backup-$NOW.sql
     329pg_dump -Fc gis > /root/gis.dmp
     330OLD=$(date --date='7 day ago' +"%Y-%m-%d")
     331rm -f /root/backup-$OLD.sql
     332EOF
     333chmod +x /usr/local/bin/backup
     334
     335cat << EOF > "/usr/local/bin/compile"
     336#!/bin/sh
     337cd ~web2py
     338python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py
     339killall cherokee
     340sleep 2
     341/etc/init.d/cherokee start
     342EOF
     343chmod +x /usr/local/bin/compile
     344
     345#@ToDo: Complete Maintenance Site
     346# (currently just disables Scheduler)
     347cat << EOF > "/usr/local/bin/maintenance"
     348#!/bin/sh
     349if [ "" != "off" ]
     350then
     351    #a2dissite maintenance
     352    #a2ensite production
     353    cd ~web2py && sudo -H -u web2py python web2py.py -K eden -Q >/dev/null 2>&1 &
     354else
     355    killall -u web2py python
     356    #a2ensite maintenance
     357    #a2dissite production
     358fi
     359killall cherokee
     360sleep 2
     361/etc/init.d/cherokee start
     362EOF
     363chmod +x /usr/local/bin/maintenance
     364
     365cat << EOF > "/usr/local/bin/pull"
     366#!/bin/sh
     367cd ~web2py/applications/eden
     368sed -i 's/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g' models/000_config.py
     369bzr pull
     370/usr/local/bin/maintenance
     371rm -rf compiled
     372cd ~web2py
     373sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
     374cd ~web2py/applications/eden
     375sed -i 's/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g' models/000_config.py
     376/usr/local/bin/maintenance off
     377/usr/local/bin/compile
     378EOF
     379chmod +x /usr/local/bin/pull
     380
     381# Change the value of prepopulate, if-necessary
     382cat << EOF > "/usr/local/bin/clean"
     383#!/bin/sh
     384cd ~web2py/applications/eden
     385rm -f databases/*
     386rm -f errors/*
     387rm -f sessions/*
     388rm -f uploads/*
     389pkill -f 'postgres: sahana sahana'
     390sudo -H -u postgres dropdb sahana
     391sed -i 's/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g' models/000_config.py
     392sed -i 's/deployment_settings.base.prepopulate = 0/deployment_settings.base.prepopulate = 1/g' models/000_config.py
     393rm -rf compiled
     394su -c - postgres "createdb -O sahana -E UTF8 sahana -T template0"
     395su -c - postgres "createlang plpgsql -d sahana"
     396su -c - postgres "psql -q -d sahana -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql"
     397su -c - postgres "psql -q -d sahana -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql"
     398cd ~web2py
     399sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
     400cd ~web2py/applications/eden
     401sed -i 's/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g' models/000_config.py
     402sed -i 's/deployment_settings.base.prepopulate = 1/deployment_settings.base.prepopulate = 0/g' models/000_config.py
     403/usr/local/bin/maintenance off
     404/usr/local/bin/compile
     405EOF
     406chmod +x /usr/local/bin/clean
     407
     408cat << EOF > "/usr/local/bin/w2p"
     409#!/bin/sh
     410cd ~web2py
     411python web2py.py -S eden -M
     412EOF
     413chmod +x /usr/local/bin/w2p
     414
     415# END
     416}}}
     417
     418== After Imaging ==
     419[http://eden.sahanafoundation.org/raw-attachment/wiki/InstallationGuidelines/Linux/Server/CherokeePostgreSQL/configure-eden-cherokee-postgis.sh configure-eden-cherokee-postgis.sh]
     420{{{
     421#!/bin/sh
     422
     423# Script to configure an Eden server
     424# - assumes that install-eden-cherokee-postgis.sh has been run
     425
     426BRANCH="~flavour/sahana-eden/trunk"
     427
     428if [ "$BRANCH" != "~flavour/sahana-eden/trunk" ]; then
     429    echo "parent_location = http://bazaar.launchpad.net/$BRANCH" > /home/web2py/applications/eden/.bzr/branch/branch.conf
     430fi
     431
     432#RAM=1
     433#if [ $RAM != 1 ]; then
     434    # @ToDo: Option to tune PostgreSQL from the default 1Gb RAM
     435    # 512
     436    #/etc/sysctl.conf
     437    #552992768->279134208
     438    #/etc/postgresql/8.4/main/postgresql.conf
     439#fi
     440
     441echo -e "What domain name should we use? : \c "
     442read DOMAIN
     443
     444echo -e "What host name should we use? : \c "
     445read hostname
     446sitename=$hostname".$DOMAIN"
     447
     448echo -e "What is the new PostgreSQL password: \c "
     449read password
     450
     451echo "Now reconfiguring system to use the hostname: $hostname"
     452
     453cd /etc
     454filename="hosts"
     455sed -i "s|localdomain localhost|localdomain localhost $hostname|" $filename
     456
     457cd /etc
     458filename="hostname"
     459echo $hostname > $filename
     460
     461cd /etc
     462filename="mailname"
     463echo $sitename >  $filename
     464
     465# Update system (in case run at a much later time than the install script)
     466apt-get update
     467apt-get upgrade -y
     468cd ~web2py
     469bzr pull
     470cd ~web2py/applications/eden
     471bzr pull
     472# -----------------------------------------------------------------------------
     473# Email
     474# -----------------------------------------------------------------------------
     475echo configure for Internet mail delivery
     476dpkg-reconfigure exim4-config
     477
     478# -----------------------------------------------------------------------------
     479# Sahana Eden
     480# -----------------------------------------------------------------------------
     481echo "Setting up Sahana"
     482
     483# Copy Templates
     484cp ~web2py/applications/eden/deployment-templates/cron/crontab ~web2py/applications/eden/cron
     485cp ~web2py/applications/eden/deployment-templates/models/000_config.py ~web2py/applications/eden/models
     486
     487sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py
     488sed -i "s|akeytochange|$sitename$password|" ~web2py/applications/eden/models/000_config.py
     489sed -i "s|127.0.0.1:8000|$sitename|" ~web2py/applications/eden/models/000_config.py
     490sed -i 's|base.cdn = False|base.cdn = True|' ~web2py/applications/eden/models/000_config.py
     491
     492# PostgreSQL
     493echo "CREATE USER sahana WITH PASSWORD '$password';" > /tmp/pgpass.sql
     494su -c - postgres "psql -q -d template1 -f /tmp/pgpass.sql"
     495rm -f /tmp/pgpass.sql
     496su -c - postgres "createdb -O sahana -E UTF8 sahana -T template0"
     497su -c - postgres "createlang plpgsql -d sahana"
     498
     499# PostGIS
     500su -c - postgres "psql -q -d sahana -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql"
     501su -c - postgres "psql -q -d sahana -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql"
     502
     503# Configure Database
     504sed -i 's|deployment_settings.database.db_type = "sqlite"|deployment_settings.database.db_type = "postgres"|' ~web2py/applications/eden/models/000_config.py
     505sed -i "s|deployment_settings.database.password = \"password\"|deployment_settings.database.password = \"$password\"|" ~web2py/applications/eden/models/000_config.py
     506sed -i 's|deployment_settings.gis.spatialdb = False|deployment_settings.gis.spatialdb = True|' ~web2py/applications/eden/models/000_config.py
     507
     508# Create the Tables & Populate with base data
     509sed -i 's|deployment_settings.base.prepopulate = 0|deployment_settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
     510sed -i 's|deployment_settings.base.migrate = False|deployment_settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py
     511cd ~web2py
     512sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
     513
     514# PostGIS the Sahana DB
     515cat << EOF > "/tmp/geometry.sql"
     516UPDATE public.gis_location SET wkt = 'POINT (' || lon || ' ' || lat || ')' WHERE gis_feature_type = 1;
     517SELECT AddGeometryColumn( 'public', 'gis_location', 'the_geom', 4326, 'GEOMETRY', 2 );
     518UPDATE public.gis_location SET the_geom = ST_SetSRID(ST_GeomFromText(wkt), 4326);
     519EOF
     520su -c - postgres "psql -q -d sahana -f /tmp/geometry.sql"
     521cat << EOF > "/tmp/autopopulate.sql"
     522CREATE OR REPLACE FUNCTION s3_update_geometry()
     523  RETURNS "trigger" AS \$$
     524  DECLARE
     525  BEGIN
     526    if (NEW.wkt != '') then
     527        NEW.the_geom = SetSRID(GeomFromText(NEW.wkt), 4326);
     528        end if;
     529
     530    RETURN NEW;
     531  END;
     532\$$  LANGUAGE 'plpgsql' VOLATILE;
     533ALTER FUNCTION s3_update_geometry() OWNER TO sahana;
     534CREATE TRIGGER s3_locations_update
     535  BEFORE INSERT
     536  ON gis_location
     537  FOR EACH ROW
     538  EXECUTE PROCEDURE s3_update_geometry();
     539
     540EOF
     541su -c - postgres "psql -q -d sahana -f /tmp/autopopulate.sql"
     542
     543# Configure for Production
     544sed -i 's|deployment_settings.base.prepopulate = 1|deployment_settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
     545sed -i 's|deployment_settings.base.migrate = True|deployment_settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py
     546cd ~web2py
     547sudo -H -u web2py python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py
     548
     549# Add Scheduler
     550sed -i 's|exit 0|cd ~web2py \&\& python web2py.py -K eden -Q >/dev/null 2>\&1 \&|' /etc/rc.local
     551echo "exit 0" >> /etc/rc.local
     552
     553#read -p "Press any key to Reboot..."
     554echo "Now rebooting.."
     555reboot
     556
     557# END
     558}}}