-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-eden-cherokee-postgis.sh
831 lines (754 loc) · 26.2 KB
/
install-eden-cherokee-postgis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
#!/bin/bash
# Script to turn a generic Debian Wheezy, Jessie, Stretch, Buster or Bullseye box into an Eden server
# with Cherokee & PostgreSQL
# - tunes PostgreSQL for 512Mb RAM (e.g. Amazon Micro (free tier))
# - run pg1024 to tune for 1Gb RAM (e.g. Amazon Small or greater)
# Which OS are we running?
read -d . DEBIAN < /etc/debian_version
if [ $DEBIAN == '11' ]; then
DEBIAN_NAME='bullseye'
PYVERSION='3'
elif [ $DEBIAN == '10' ]; then
DEBIAN_NAME='buster'
PYVERSION='3'
elif [ $DEBIAN == '9' ]; then
DEBIAN_NAME='stretch'
PYVERSION='2'
elif [ $DEBIAN == '8' ]; then
DEBIAN_NAME='jessie'
PYVERSION='2'
else
DEBIAN_NAME='wheezy'
PYVERSION='2'
fi
# Update system
apt-get update
apt-get -y upgrade
apt-get clean
# Install Admin Tools
apt-get -y install "at" "curl" "dos2unix" "htop" "lrzsz" "mlocate" "p7zip" "psmisc" "pwgen" "rcconf" "sudo" "telnet" "unzip" "vim"
if [ $DEBIAN == '11' ]; then
apt-get -y install elinks net-tools
elif [ $DEBIAN == '10' ]; then
apt-get -y install elinks net-tools
elif [ $DEBIAN == '9' ]; then
apt-get -y install elinks net-tools
else
apt-get -y install elinks-lite
fi
apt-get clean
# Git
apt-get -y install git-core
apt-get clean
# Email
apt-get -y install exim4-config exim4-daemon-light
apt-get clean
#########
# Python
#########
# Install Libraries
if [ $DEBIAN == '11' ]; then
apt-get -y install libgeos-c1v5
elif [ $DEBIAN == '10' ]; then
apt-get -y install libgeos-c1v5
elif [ $DEBIAN == '9' ]; then
apt-get -y install libgeos-c1v5
else
apt-get -y install libgeos-c1
fi
# Install Python
if [ $PYVERSION == '2' ]; then
PIP=pip
#apt-get -y install python2.7
apt-get -y install python-dev python-pip python-setuptools
# 100 Mb of diskspace due to deps, so only if you want an advanced shell
#apt-get -y install ipython
apt-get clean
#apt-get -y install python-lxml python-dateutil
apt-get clean
apt-get -y install python-serial
#apt-get -y install python-imaging python-reportlab
#apt-get -y install python-imaging
#apt-get -y install python-matplotlib
#apt-get -y install python-requests
#apt-get -y install python-xlwt
else
PIP=pip3
apt-get -y install "python3-dev" "python3-pip" "python3-setuptools" "python3-mysqldb"
#apt-get -y install "python3-lxml" "python3-dateutil"
apt-get -y install "python3-serial"
#apt-get -y install "python3-pil"
#apt-get -y install "python3-matplotlib"
#apt-get -y install "python3-requests"
#apt-get -y install "python3-xlwt"
update-alternatives --install /usr/bin/python python /usr/bin/python2 1
update-alternatives --install /usr/bin/python python /usr/bin/python3 2
fi
apt-get -y install build-essential
apt-get clean
$PIP install lxml
$PIP install python-dateutil
$PIP install pillow
$PIP install requests
$PIP install xlwt
$PIP install geopy
# Upgrade ReportLab for Percentage support
#apt-get remove -y python-reportlab
#wget --no-check-certificate http://pypi.python.org/packages/source/r/reportlab/reportlab-3.3.0.tar.gz
#tar zxvf reportlab-3.3.0.tar.gz
#cd reportlab-3.3.0
#python setup.py install
#cd ..
$PIP install reportlab
# Upgrade Shapely for Simplify enhancements
#apt-get remove -y python-shapely
apt-get -y install libgeos-dev
#wget --no-check-certificate https://pypi.python.org/packages/e6/23/03ea2c965fe5ded97c0dd97c2cd659f1afb5c21f388ec68012d6d981cb7c/Shapely-1.5.17.tar.gz
#tar zxvf Shapely-1.5.17.tar.gz
#cd Shapely-1.5.17
#python setup.py install
#cd ..
$PIP install shapely
# Upgrade XLRD for XLS import support
#apt-get remove -y python-xlrd
#wget --no-check-certificate http://pypi.python.org/packages/source/x/xlrd/xlrd-0.9.4.tar.gz
#tar zxvf xlrd-0.9.4.tar.gz
#cd xlrd-0.9.4
#python setup.py install
#cd ..
$PIP install xlrd
#########
# Web2Py
#########
apt-get -y install libodbc1
# Install Web2Py
adduser --system --disabled-password web2py
addgroup web2py
cd /home
env GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/web2py/web2py.git
cd web2py
# 2.21.2
git reset --hard 31905858b
git submodule update --init --recursive
ln -s /home/web2py ~
cp -f /home/web2py/handlers/wsgihandler.py /home/web2py
cat << EOF > "/home/web2py/routes.py"
#!/usr/bin/python
default_application = 'eden'
default_controller = 'default'
default_function = 'index'
routes_onerror = [
('eden/400', '!'),
('eden/401', '!'),
('eden/509', '!'),
('eden/*', '/eden/errors/index'),
('*/*', '/eden/errors/index'),
]
EOF
# Configure Matplotlib
mkdir /home/web2py/.matplotlib
chown web2py /home/web2py/.matplotlib
echo "os.environ['MPLCONFIGDIR'] = '/home/web2py/.matplotlib'" >> /home/web2py/wsgihandler.py
sed -i 's|TkAgg|Agg|' /etc/matplotlibrc
##############
# Sahana Eden
##############
# Install Sahana Eden
cd /home/web2py
cd applications
# @ToDo: Stable branch
env GIT_SSL_NO_VERIFY=true git clone https://github.com/sahana/eden-stable.git eden
# Fix permissions
chown web2py ~web2py
chown web2py ~web2py/applications/admin/cache
chown web2py ~web2py/applications/admin/cron
chown web2py ~web2py/applications/admin/databases
chown web2py ~web2py/applications/admin/errors
chown web2py ~web2py/applications/admin/sessions
chown web2py ~web2py/applications/eden
chown web2py ~web2py/applications/eden/cache
chown web2py ~web2py/applications/eden/cron
mkdir -p ~web2py/applications/eden/databases
chown web2py ~web2py/applications/eden/databases
mkdir -p ~web2py/applications/eden/errors
chown web2py ~web2py/applications/eden/errors
chown web2py ~web2py/applications/eden/models
mkdir -p ~web2py/applications/eden/sessions
chown web2py ~web2py/applications/eden/sessions
chown web2py ~web2py/applications/eden/static/fonts
chown web2py ~web2py/applications/eden/static/img/markers
mkdir -p ~web2py/applications/eden/static/cache/chart
chown web2py -R ~web2py/applications/eden/static/cache
mkdir -p ~web2py/applications/eden/uploads/gis_cache
mkdir -p ~web2py/applications/eden/uploads/images
mkdir -p ~web2py/applications/eden/uploads/tracks
chown web2py ~web2py/applications/eden/uploads
chown web2py ~web2py/applications/eden/uploads/gis_cache
chown web2py ~web2py/applications/eden/uploads/images
chown web2py ~web2py/applications/eden/uploads/tracks
ln -s /home/web2py/applications/eden /home/web2py
ln -s /home/web2py/applications/eden ~
##########
# Cherokee
##########
# Old Debian version
#echo "deb http://apt.balocco.name squeeze main" >> /etc/apt/sources.list
#curl http://apt.balocco.name/key.asc | apt-key add -
#apt-get update
#apt-get -y --force-yes install cherokee libcherokee-mod-rrd
#apt-get clean
apt-get install -y autoconf automake libtool gettext rrdtool
cd /tmp
#env GIT_SSL_NO_VERIFY=true git clone --recursive https://github.com/cherokee/webserver.git
#cd webserver
wget https://github.com/cherokee/webserver/archive/master.zip
unzip master.zip
cd webserver-master
if [ $DEBIAN == '11' ]; then
apt-get install -y libtool-bin
elif [ $DEBIAN == '10' ]; then
apt-get install -y libtool-bin
elif [ $DEBIAN == '9' ]; then
apt-get install -y libtool-bin
elif [ $DEBIAN == '8' ]; then
apt-get install -y libtool-bin
fi
sh ./autogen.sh --prefix=/usr --localstatedir=/var --sysconfdir=/etc
make
make install
mkdir /var/log/cherokee
chown www-data:www-data /var/log/cherokee
mkdir -p /var/lib/cherokee/graphs
chown www-data:www-data -R /var/lib/cherokee
cat << EOF > "/etc/init.d/cherokee"
#! /bin/sh
#
# start/stop Cherokee web server
### BEGIN INIT INFO
# Provides: cherokee
# Required-Start: \$remote_fs \$network \$syslog
# Required-Stop: \$remote_fs \$network \$syslog
# Should-Start: \$named
# Should-Stop: \$named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the Cherokee Web server
# Description: Start the Cherokee Web server
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/cherokee
NAME=cherokee
PIDFILE=/var/run/cherokee.pid
. /lib/lsb/init-functions
set -e
test -x \$DAEMON || exit 0
case "\$1" in
start)
echo "Starting \$NAME web server "
start-stop-daemon --start --oknodo --pidfile \$PIDFILE --exec \$DAEMON -b
;;
stop)
echo "Stopping \$NAME web server "
start-stop-daemon --stop --oknodo --pidfile \$PIDFILE --exec \$DAEMON
rm -f \$PIDFILE
;;
restart)
\$0 stop
sleep 1
\$0 start
;;
reload|force-reload)
echo "Reloading web server "
if [ -f \$PIDFILE ]
then
PID=\$(cat \$PIDFILE)
if ps p \$PID | grep \$NAME >/dev/null 2>&1
then
kill -HUP \$PID
else
echo "PID present, but \$NAME not found at PID \$PID - Cannot reload"
exit 1
fi
else
echo "No PID file present for \$NAME - Cannot reload"
exit 1
fi
;;
status)
# Strictly, LSB mandates us to return indicating the different statuses,
# but that's not exactly Debian compatible - For further information:
# http://www.freestandards.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/iniscrptact.html
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=208010
# ...So we just inform to the invoker and return success.
echo "\$NAME web server status"
if [ -e \$PIDFILE ] ; then
PROCNAME=\$(ps -p \$(cat \$PIDFILE) -o comm=)
if [ "x\$PROCNAME" = "x" ]; then
echo "Not running, but PID file present"
else
if [ "\$PROCNAME" = "\$NAME" ]; then
echo "Running"
else
echo "PID file points to process '\$PROCNAME', not '\$NAME'"
fi
fi
else
if PID=\$(pidofproc \$DAEMON); then
echo "Running (PID \$PID), but PIDFILE not present"
else
echo "Not running\t"
fi
fi
;;
*)
N=/etc/init.d/\$NAME
echo "Usage: \$N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0
EOF
chmod +x /etc/init.d/cherokee
update-rc.d cherokee defaults
CHEROKEE_CONF="/etc/cherokee/cherokee.conf"
# Install uWSGI
#apt-get install -y libxml2-dev
cd /tmp
wget https://projects.unbit.it/downloads/uwsgi-2.0.18.tar.gz
tar zxvf uwsgi-2.0.18.tar.gz
cd uwsgi-2.0.18
#cd uwsgi-1.2.6/buildconf
#wget http://eden.sahanafoundation.org/downloads/uwsgi_build.ini
#cd ..
#sed -i "s|, '-Werror'||" uwsgiconfig.py
#python uwsgiconfig.py --build uwsgi_build
python uwsgiconfig.py --build pyonly
cp uwsgi /usr/local/bin
# Configure uwsgi
## Log rotation
cat << EOF > "/etc/logrotate.d/uwsgi"
/var/log/uwsgi/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
}
EOF
## Add Scheduler config
cat << EOF > "/home/web2py/run_scheduler.py"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
if '__file__' in globals():
path = os.path.dirname(os.path.abspath(__file__))
os.chdir(path)
else:
path = os.getcwd() # Seems necessary for py2exe
sys.path = [path]+[p for p in sys.path if not p==path]
# import gluon.import_all ##### This should be uncommented for py2exe.py
import gluon.widget
from gluon.shell import run
# Start Web2py Scheduler -- Note the app name is hardcoded!
if __name__ == '__main__':
run('eden',True,True,None,False,"from gluon import current; current._scheduler.loop()")
EOF
cat << EOF > "/home/web2py/uwsgi.ini"
[uwsgi]
uid = web2py
gid = web2py
chdir = /home/web2py/
module = wsgihandler
mule = run_scheduler.py
workers = 4
cheap = true
idle = 1000
harakiri = 1000
pidfile = /var/run/uwsgi-prod.pid
daemonize = /var/log/uwsgi/prod.log
socket = 127.0.0.1:59025
master = true
EOF
mkdir -p /var/log/uwsgi
chown web2py: /var/log/uwsgi
# Init script for uwsgi
cat << EOF > "/etc/init.d/uwsgi-prod"
#! /bin/bash
# /etc/init.d/uwsgi-prod
#
daemon=/usr/local/bin/uwsgi
pid=/var/run/uwsgi-prod.pid
args="/home/web2py/uwsgi.ini"
# Carry out specific functions when asked to by the system
case "\$1" in
start)
echo "Starting uwsgi"
touch \$pid
chmod 600 \$pid
start-stop-daemon -p \$pid --start --exec \$daemon -- \$args
;;
stop)
echo "Stopping script uwsgi"
start-stop-daemon --signal INT -p \$pid --stop \$daemon -- \$args
;;
restart)
\$0 stop
sleep 1
\$0 start
;;
reload)
echo "Reloading conf"
kill -HUP \`cat \$pid\`
;;
*)
echo "Usage: /etc/init.d/uwsgi {start|stop|restart|reload}"
exit 1
;;
esac
exit 0
EOF
chmod a+x /etc/init.d/uwsgi-prod
update-rc.d uwsgi-prod defaults
# Configure Cherokee
# If using an Alternate Theme then can add a rule for that: static/themes/<theme>/img
mv "$CHEROKEE_CONF" /tmp
cat << EOF > "$CHEROKEE_CONF"
config!version = 001002002
server!bind!1!port = 80
server!collector = rrd
server!fdlimit = 10240
server!group = www-data
server!ipv6 = 0
server!keepalive = 1
server!keepalive_max_requests = 500
server!panic_action = /usr/share/cherokee/cherokee-panic
server!pid_file = /var/run/cherokee.pid
server!server_tokens = product
server!timeout = 1000
server!user = www-data
vserver!10!collector!enabled = 1
vserver!10!directory_index = index.html
vserver!10!document_root = /var/www
vserver!10!error_writer!filename = /var/log/cherokee/cherokee.error
vserver!10!error_writer!type = file
vserver!10!logger = combined
vserver!10!logger!access!buffsize = 16384
vserver!10!logger!access!filename = /var/log/cherokee/cherokee.access
vserver!10!logger!access!type = file
vserver!10!nick = default
vserver!10!rule!10!handler = common
vserver!10!rule!10!handler!iocache = 1
vserver!10!rule!10!match = default
vserver!20!collector!enabled = 1
vserver!20!directory_index = index.html
vserver!20!document_root = /var/www
vserver!20!error_writer!filename = /var/log/cherokee/cherokee.error
vserver!20!error_writer!type = file
vserver!20!logger = combined
vserver!20!logger!access!buffsize = 16384
vserver!20!logger!access!filename = /var/log/cherokee/cherokee.access
vserver!20!logger!access!type = file
vserver!20!match = wildcard
vserver!20!match!domain!1 = *
vserver!20!match!nick = 0
vserver!20!nick = maintenance
vserver!20!rule!210!handler = file
vserver!20!rule!210!match = fullpath
vserver!20!rule!210!match!fullpath!1 = /maintenance.html
vserver!20!rule!110!handler = redir
vserver!20!rule!110!handler!rewrite!10!regex = ^/*
vserver!20!rule!110!handler!rewrite!10!show = 1
vserver!20!rule!110!handler!rewrite!10!substring = /maintenance.html
vserver!20!rule!110!match = directory
vserver!20!rule!110!match!directory = /
vserver!20!rule!10!handler = common
vserver!20!rule!10!handler!iocache = 1
vserver!20!rule!10!match = default
vserver!30!collector!enabled = 1
vserver!30!directory_index = index.html
vserver!30!document_root = /var/www
vserver!30!error_handler = error_redir
vserver!30!error_handler!503!show = 0
vserver!30!error_handler!503!url = /maintenance.html
vserver!30!error_writer!filename = /var/log/cherokee/cherokee.error
vserver!30!error_writer!type = file
vserver!30!logger = combined
vserver!30!logger!access!buffsize = 16384
vserver!30!logger!access!filename = /var/log/cherokee/cherokee.access
vserver!30!logger!access!type = file
vserver!30!match = wildcard
vserver!30!match!domain!1 = *
vserver!30!match!nick = 0
vserver!30!nick = Production
vserver!30!rule!700!expiration = epoch
vserver!30!rule!700!expiration!caching = public
vserver!30!rule!700!expiration!caching!must-revalidate = 1
vserver!30!rule!700!expiration!caching!no-store = 0
vserver!30!rule!700!expiration!caching!no-transform = 0
vserver!30!rule!700!expiration!caching!proxy-revalidate = 1
vserver!30!rule!700!handler = common
vserver!30!rule!700!handler!allow_dirlist = 0
vserver!30!rule!700!handler!allow_pathinfo = 0
vserver!30!rule!700!match = fullpath
vserver!30!rule!700!match!fullpath!1 = /maintenance.html
vserver!30!rule!500!document_root = /home/web2py/applications/eden/static
vserver!30!rule!500!encoder!deflate = allow
vserver!30!rule!500!encoder!gzip = allow
vserver!30!rule!500!expiration = time
vserver!30!rule!500!expiration!time = 7d
vserver!30!rule!500!handler = file
vserver!30!rule!500!match = fullpath
vserver!30!rule!500!match!fullpath!1 = /favicon.ico
vserver!30!rule!500!match!fullpath!2 = /robots.txt
vserver!30!rule!500!match!fullpath!3 = /crossdomain.xml
vserver!30!rule!400!document_root = /home/web2py/applications/eden/static/img
vserver!30!rule!400!encoder!deflate = forbid
vserver!30!rule!400!encoder!gzip = forbid
vserver!30!rule!400!expiration = time
vserver!30!rule!400!expiration!caching = public
vserver!30!rule!400!expiration!caching!must-revalidate = 0
vserver!30!rule!400!expiration!caching!no-store = 0
vserver!30!rule!400!expiration!caching!no-transform = 0
vserver!30!rule!400!expiration!caching!proxy-revalidate = 0
vserver!30!rule!400!expiration!time = 7d
vserver!30!rule!400!handler = file
vserver!30!rule!400!match = directory
vserver!30!rule!400!match!directory = /eden/static/img/
vserver!30!rule!400!match!final = 1
vserver!30!rule!300!document_root = /home/web2py/applications/eden/static
vserver!30!rule!300!encoder!deflate = allow
vserver!30!rule!300!encoder!gzip = allow
vserver!30!rule!300!expiration = epoch
vserver!30!rule!300!expiration!caching = public
vserver!30!rule!300!expiration!caching!must-revalidate = 1
vserver!30!rule!300!expiration!caching!no-store = 0
vserver!30!rule!300!expiration!caching!no-transform = 0
vserver!30!rule!300!expiration!caching!proxy-revalidate = 1
vserver!30!rule!300!handler = file
vserver!30!rule!300!match = directory
vserver!30!rule!300!match!directory = /eden/static/
vserver!30!rule!300!match!final = 1
vserver!30!rule!200!encoder!deflate = allow
vserver!30!rule!200!encoder!gzip = allow
vserver!30!rule!200!handler = uwsgi
vserver!30!rule!200!handler!balancer = round_robin
vserver!30!rule!200!handler!balancer!source!10 = 1
vserver!30!rule!200!handler!check_file = 0
vserver!30!rule!200!handler!error_handler = 1
vserver!30!rule!200!handler!modifier1 = 0
vserver!30!rule!200!handler!modifier2 = 0
vserver!30!rule!200!handler!pass_req_headers = 1
vserver!30!rule!200!match = directory
vserver!30!rule!200!match!directory = /
vserver!30!rule!100!handler = common
vserver!30!rule!100!handler!iocache = 1
vserver!30!rule!100!match = default
source!1!env_inherited = 1
source!1!group = web2py
source!1!host = 127.0.0.1:59025
source!1!interpreter = /usr/local/bin/uwsgi -s 127.0.0.1:59025 -x /home/web2py/uwsgi.xml
source!1!nick = uWSGI 1
source!1!timeout = 1000
source!1!type = host
source!1!user = web2py
EOF
grep 'icons!' /tmp/cherokee.conf >> "$CHEROKEE_CONF"
grep 'mime!' /tmp/cherokee.conf >> "$CHEROKEE_CONF"
cat << EOF >> "$CHEROKEE_CONF"
admin!ows!enabled = 0
EOF
# For a static home page, push 400->500 & 300->400 & insert this
#vserver!30!rule!300!document_root = /home/web2py/applications/eden/static
#vserver!30!rule!300!handler = redir
#vserver!30!rule!300!handler!rewrite!10!regex = ^.*$
#vserver!30!rule!300!handler!rewrite!10!show = 1
#vserver!30!rule!300!handler!rewrite!10!substring = /eden/static/index.html
#vserver!30!rule!300!match = and
#vserver!30!rule!300!match!final = 1
#vserver!30!rule!300!match!left = fullpath
#vserver!30!rule!300!match!left!fullpath!1 = /
#vserver!30!rule!300!match!right = not
#vserver!30!rule!300!match!right!right = header
#vserver!30!rule!300!match!right!right!complete = 0
#vserver!30!rule!300!match!right!right!header = Cookie
#vserver!30!rule!300!match!right!right!match = re
#vserver!30!rule!300!match!right!right!type = regex
cat << EOF > "/var/www/maintenance.html"
<html><body><h1>Site Maintenance</h1>Please try again later...</body></html>
EOF
/etc/init.d/cherokee restart
############
# PostgreSQL
############
cat << EOF > "/etc/apt/sources.list.d/pgdg.list"
deb http://apt.postgresql.org/pub/repos/apt/ $DEBIAN_NAME-pgdg main
EOF
wget --no-check-certificate https://www.postgresql.org/media/keys/ACCC4CF8.asc
apt-key add ACCC4CF8.asc
apt-get update
case $DEBIAN in
10)
apt-get -y install "postgresql-11" "pgtop"
apt-get -y install "postgresql-11-postgis-2.5"
PGHOME=/etc/postgresql/11
;;
*)
# Psycopg2 versions in stretch/jessie can have problems with PG10+
apt-get -y install "postgresql-9.6" "ptop" "pgtop"
apt-get -y install "postgresql-9.6-postgis-2.3"
PGHOME=/etc/postgresql/9.6
;;
esac
if [ $PYVERSION == '2' ]; then
apt-get -y install "python-psycopg2"
else
apt-get -y install "python3-psycopg2"
fi
# Tune PostgreSQL
cat << EOF >> "/etc/sysctl.conf"
## Increase Shared Memory available for PostgreSQL
# 512Mb
#kernel.shmmax = 279134208
# 1024Mb (may need more)
kernel.shmmax = 552992768
kernel.shmall = 2097152
EOF
#sysctl -w kernel.shmmax=279134208 # For 512 MB RAM
sysctl -w kernel.shmmax=552992768 # For 1024 MB RAM
sysctl -w kernel.shmall=2097152
sed -i 's|#track_counts = on|track_counts = on|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|#autovacuum = on|autovacuum = on|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|max_connections = 100|max_connections = 20|' /etc/postgresql/9.6/main/postgresql.conf
# 1024Mb RAM: (e.g. t2.micro)
sed -i 's|#effective_cache_size = 4GB|effective_cache_size = 512MB|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|#work_mem = 4MB|work_mem = 8MB|' /etc/postgresql/9.6/main/postgresql.conf
# If only 512 RAM, activate post-install via pg512 script
#####################
# Management scripts
#####################
cat << EOF > "/usr/local/bin/backup"
#!/bin/sh
mkdir /var/backups/eden
chown postgres /var/backups/eden
NOW=\$(date +"%Y-%m-%d")
su -c - postgres "pg_dump -c sahana > /var/backups/eden/sahana-\$NOW.sql"
#su -c - postgres "pg_dump -Fc gis > /var/backups/eden/gis.dmp"
OLD=\$(date --date='7 day ago' +"%Y-%m-%d")
rm -f /var/backups/eden/sahana-\$OLD.sql
mkdir /var/backups/eden/uploads
tar -cf /var/backups/eden/uploads/uploadsprod-\$NOW.tar -C /home/web2py/applications/eden ./uploads
bzip2 /var/backups/eden/uploads/uploadsprod-\$NOW.tar
rm -f /var/backups/eden/uploads/uploadsprod-\$OLD.tar.bz2
EOF
chmod +x /usr/local/bin/backup
cat << EOF > "/usr/local/bin/compile"
#!/bin/bash
/etc/init.d/uwsgi-prod stop
cd ~web2py
python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
/etc/init.d/uwsgi-prod start
EOF
chmod +x /usr/local/bin/compile
cat << EOF > "/usr/local/bin/pull"
#!/bin/sh
/etc/init.d/uwsgi-prod stop
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
git reset --hard HEAD
git pull
git submodule update --recursive
rm -rf compiled
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
cd ~web2py
python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
/etc/init.d/uwsgi-prod start
EOF
chmod +x /usr/local/bin/pull
cat << EOF > "/usr/local/bin/migrate"
#!/bin/sh
/etc/init.d/uwsgi-prod stop
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
rm -rf compiled
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
cd ~web2py
python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
/etc/init.d/uwsgi-prod start
EOF
chmod +x /usr/local/bin/migrate
cat << EOF > "/usr/local/bin/revert"
#!/bin/sh
git reset --hard HEAD
EOF
chmod +x /usr/local/bin/revert
cat << EOF > "/usr/local/bin/w2p"
#!/bin/sh
cd ~web2py
python web2py.py -S eden -M
EOF
chmod +x /usr/local/bin/w2p
cat << EOF2 > "/usr/local/bin/clean"
#!/bin/sh
/etc/init.d/uwsgi-prod stop
cd ~web2py/applications/eden
rm -rf databases/*
rm -f errors/*
rm -rf sessions/*
rm -rf uploads/*
pkill -f 'postgres: sahana sahana'
sudo -H -u postgres dropdb sahana
sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
sed -i 's/settings.base.prepopulate = 0/#settings.base.prepopulate = 0/g' models/000_config.py
rm -rf compiled
su -c - postgres "createdb -O sahana -E UTF8 sahana -T template0"
#su -c - postgres "createlang plpgsql -d sahana"
#su -c - postgres "psql -q -d sahana -f /usr/share/postgresql/9.6/extension/postgis--2.3.0.sql"
su -c - postgres "psql -q -d sahana -c 'CREATE EXTENSION postgis;'"
su -c - postgres "psql -q -d sahana -c 'grant all on geometry_columns to sahana;'"
su -c - postgres "psql -q -d sahana -c 'grant all on spatial_ref_sys to sahana;'"
cd ~web2py
sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
cd ~web2py/applications/eden
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/g' models/000_config.py
cd ~web2py
python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
/etc/init.d/uwsgi-prod start
if [ -e /home/data/import.py ]; then
sudo -H -u web2py python web2py.py -S eden -M -R /home/data/import.py
fi
EOF2
chmod +x /usr/local/bin/clean
cat << EOF > "/usr/local/bin/pg1024"
#!/bin/sh
sed -i 's|kernel.shmmax = 279134208|#kernel.shmmax = 279134208|' /etc/sysctl.conf
sed -i 's|#kernel.shmmax = 552992768|kernel.shmmax = 552992768|' /etc/sysctl.conf
sysctl -w kernel.shmmax=552992768
sed -i 's|shared_buffers = 128MB|shared_buffers = 256MB|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|effective_cache_size = 256MB|effective_cache_size = 512MB|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|work_mem = 4MB|work_mem = 8MB|' /etc/postgresql/9.6/main/postgresql.conf
/etc/init.d/postgresql restart
EOF
chmod +x /usr/local/bin/pg1024
cat << EOF > "/usr/local/bin/pg512"
#!/bin/sh
sed -i 's|#kernel.shmmax = 279134208|kernel.shmmax = 279134208|' /etc/sysctl.conf
sed -i 's|kernel.shmmax = 552992768|#kernel.shmmax = 552992768|' /etc/sysctl.conf
sysctl -w kernel.shmmax=279134208
sed -i 's|shared_buffers = 256MB|shared_buffers = 128MB|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|effective_cache_size = 512MB|effective_cache_size = 256MB|' /etc/postgresql/9.6/main/postgresql.conf
sed -i 's|work_mem = 8MB|work_mem = 4MB|' /etc/postgresql/9.6/main/postgresql.conf
/etc/init.d/postgresql restart
EOF
chmod +x /usr/local/bin/pg512
apt-get clean
# END