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