InstallationGuidelines/Linux/Server/ApachePostgresqlDebian8: configure-eden-apache-postgis-debian8.sh

File configure-eden-apache-postgis-debian8.sh, 5.0 KB (added by arminr, 7 years ago)
Line 
1#!/bin/sh
2# Script to configure an Eden server
3# - assumes that install-eden-apache-postgis-debian8.sh has been run
4
5# Defines for sahana eden installation
6hostanddomain="127.0.0.1"
7template="default"
8key="testkey"
9database_type="postgres"
10
11# Defines for database connection
12database_name="sahana"
13database_port="5432"
14database_user="sahana"
15database_password="sahana"
16
17#########
18# Eden pre-installation of database
19#########
20#copy config template
21cp ~web2py/applications/eden/modules/templates/000_config.py ~web2py/applications/eden/models
22# adopt template according to defined values
23sed -i "s|settings.base.template = \"default\"|settings.base.template = \"$template\"|" ~web2py/applications/eden/models/000_config.py
24sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py
25sed -i "s|akeytochange|$key|" ~web2py/applications/eden/models/000_config.py
26sed -i "s|#settings.base.public_url = \"http://127.0.0.1:8000\"|settings.base.public_url = \"http://$hostanddomain\"|" ~web2py/applications/eden/models/000_config.py
27#? wherefor
28sed -i 's|#settings.base.cdn = True|settings.base.cdn = True|' ~web2py/applications/eden/models/000_config.py
29
30#########
31# PostgreSQL
32#########
33cd ~web2py
34#-------
35#drop db if one already exists - before we have to stop the wsgi process!!
36/etc/init.d/apache2 stop
37echo "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$database_name';" > /tmp/delete_current_connections.sql
38su - postgres -c "psql -q -p $database_port -f /tmp/delete_current_connections.sql"
39su - postgres -c "dropdb -p $database_port $database_name"
40echo "database dropped"
41echo "CREATE USER $database_user WITH PASSWORD '$database_password';" > /tmp/pgpass.sql
42su - postgres -c "psql -q -p $database_port -d template1 -f /tmp/pgpass.sql"
43#template 1? - for roles
44rm -f /tmp/pgpass.sql
45su - postgres -c "createdb -p $database_port -O $database_user -E UTF8 $database_name -T template0"
46# PostGIS
47su - postgres -c "psql -q -p $database_port -d $database_name -f /usr/share/postgresql/9.4/contrib/postgis-2.1/postgis.sql"
48su - postgres -c "psql -q -p $database_port -d $database_name -f /usr/share/postgresql/9.4/contrib/postgis-2.1/spatial_ref_sys.sql"
49su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on geometry_columns to $database_user;'"
50# maybe new to postgis 2.x
51su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on geography_columns to $database_user;'"
52su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on spatial_ref_sys to $database_user;'"
53# maybe the following is not needed
54su - postgres -c "psql -q -p $database_port -d $database_name -c 'ALTER DATABASE $database_name OWNER TO $database_user;'"
55
56#########
57# Eden post-installation of database
58#########
59# Disable comment on postgres configuration line
60sed -i 's|#settings.database.db_type = "postgres"|settings.database.db_type = "postgres"|' ~web2py/applications/eden/models/000_config.py
61# Defining password for database connection
62sed -i "s|#settings.database.password = \"password\"|settings.database.password = \"$database_password\"|" ~web2py/applications/eden/models/000_config.py
63# Enable spatial settings
64sed -i 's|#settings.gis.spatialdb = True|settings.gis.spatialdb = True|' ~web2py/applications/eden/models/000_config.py
65# Create the Tables & Populate with base data
66# next line from mysql installation instruction - needed?
67sed -i 's|settings.base.prepopulate = 0|#settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
68#sed -i 's|settings.base.prepopulate = 0|settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
69# If invoked a second time maybe it stucks on commented line!
70#sed -i 's|#settings.base.prepopulate = 0|settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py
71sed -i 's|settings.base.migrate = False|settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py
72cd ~web2py
73# Delete .table entries for database which exists before, cause otherwise the new database will not be prepopulated
74rm -rf ~web2py/applications/eden/databases/*
75rm -rf ~web2py/applications/eden/compiled
76sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
77# Next line needed?
78sed -i 's|#settings.base.prepopulate = 0|settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
79#sed -i 's|settings.base.prepopulate = 1|settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py
80sed -i 's|settings.base.migrate = True|settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py
81cd ~web2py
82# notice - after compile the apache2 process is restarted!!!
83sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
84# Schedule backups for 02:01 daily
85echo "1 2 * * * root /usr/local/bin/backup" >> "/etc/crontab"
86#read -p "Press any key to Reboot..."
87#########
88# Reboot? - why
89#########
90echo "Now rebooting.."
91#reboot