1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # Script to turn a generic Jessie box into an Eden server
|
---|
4 | # with apache & PostgreSQL
|
---|
5 | # - tunes PostgreSQL for 512Mb RAM (e.g. Amazon Micro (free tier))
|
---|
6 | # - run pg1024 to tune for 1Gb RAM (e.g. Amazon Small or greater)
|
---|
7 |
|
---|
8 | #configuration for specific installation - relevant for database cleaning script
|
---|
9 | database_name="sahana"
|
---|
10 | database_port="5432"
|
---|
11 | database_user="sahana"
|
---|
12 | database_password="sahana"
|
---|
13 |
|
---|
14 | #versions of external libraries
|
---|
15 | reportlab_version="3.2.0"
|
---|
16 | Shapely_version="1.5.13"
|
---|
17 | xlrd_version="0.9.4"
|
---|
18 |
|
---|
19 | #configuration of apache24 config files
|
---|
20 | extension='.conf'
|
---|
21 | use_proxy="false"
|
---|
22 | http_proxy_host="10.240.20.164"
|
---|
23 | http_proxy_port="8080"
|
---|
24 | https_proxy_host="10.240.20.164"
|
---|
25 | https_proxy_port="8080"
|
---|
26 |
|
---|
27 | #apache confs
|
---|
28 | hostname=""
|
---|
29 | DOMAIN=""
|
---|
30 | hostname_error="sahana_error"
|
---|
31 | hostname_access="sahana_access"
|
---|
32 | GRANT=""
|
---|
33 |
|
---|
34 | if [ $use_proxy == 'true' ]; then
|
---|
35 | #set proxy env for wget from shell
|
---|
36 | export http_proxy=http://$http_proxy_host:$http_proxy_port
|
---|
37 | export https_proxy=http://$https_proxy_host:$https_proxy_port
|
---|
38 |
|
---|
39 | #for git access behind proxy
|
---|
40 | git config --global http.proxy http://$http_proxy_host:$http_proxy_port
|
---|
41 | git config --global https.proxy http://$https_proxy_host:$https_proxy_port
|
---|
42 | fi
|
---|
43 |
|
---|
44 | #########
|
---|
45 | # Standard debian packages
|
---|
46 | #########
|
---|
47 | # Update debian system
|
---|
48 | apt-get update
|
---|
49 | apt-get -y upgrade
|
---|
50 | apt-get clean
|
---|
51 | # Install Admin Tools
|
---|
52 | apt-get -y install unzip psmisc mlocate telnet lrzsz vim elinks-lite rcconf htop sudo p7zip dos2unix curl
|
---|
53 | apt-get clean
|
---|
54 | # Git
|
---|
55 | apt-get -y install git-core
|
---|
56 | apt-get clean
|
---|
57 | # Email
|
---|
58 | apt-get -y install exim4-config exim4-daemon-light
|
---|
59 | apt-get clean
|
---|
60 |
|
---|
61 | #########
|
---|
62 | # Python debian packages
|
---|
63 | #########
|
---|
64 | # Install Libraries
|
---|
65 | apt-get -y install libgeos-c1
|
---|
66 | # Install Python
|
---|
67 | #apt-get -y install python2.7
|
---|
68 | apt-get -y install python-dev
|
---|
69 | # 100 Mb of diskspace due to deps, so only if you want an advanced shell
|
---|
70 | #apt-get -y install ipython
|
---|
71 | apt-get clean
|
---|
72 | apt-get -y install python-lxml python-setuptools python-dateutil
|
---|
73 | apt-get clean
|
---|
74 | apt-get -y install python-serial
|
---|
75 | #apt-get -y install python-imaging python-reportlab
|
---|
76 | apt-get -y install python-imaging
|
---|
77 | apt-get -y install python-matplotlib
|
---|
78 | apt-get -y install python-requests
|
---|
79 | apt-get -y install python-xlwt
|
---|
80 | apt-get -y install build-essential
|
---|
81 | apt-get clean
|
---|
82 |
|
---|
83 | #########
|
---|
84 | # External packages
|
---|
85 | #########
|
---|
86 | # Upgrade ReportLab for Percentage support
|
---|
87 | #apt-get remove -y python-reportlab
|
---|
88 | wget --no-check-certificate http://pypi.python.org/packages/source/r/reportlab/reportlab-$reportlab_version.tar.gz
|
---|
89 | tar zxvf reportlab-$reportlab_version.tar.gz
|
---|
90 | cd reportlab-$reportlab_version
|
---|
91 | python setup.py install
|
---|
92 | cd ..
|
---|
93 |
|
---|
94 | # Upgrade Shapely for Simplify enhancements
|
---|
95 | #apt-get remove -y python-shapely
|
---|
96 | apt-get -y install libgeos-dev
|
---|
97 | wget --no-check-certificate http://pypi.python.org/packages/source/S/Shapely/Shapely-$Shapely_version.tar.gz
|
---|
98 | tar zxvf Shapely-$Shapely_version.tar.gz
|
---|
99 | cd Shapely-$Shapely_version
|
---|
100 | python setup.py install
|
---|
101 | cd ..
|
---|
102 |
|
---|
103 | # Upgrade XLRD for XLS import support
|
---|
104 | #apt-get remove -y python-xlrd
|
---|
105 | wget --no-check-certificate http://pypi.python.org/packages/source/x/xlrd/xlrd-$xlrd_version.tar.gz
|
---|
106 | tar zxvf xlrd-$xlrd_version.tar.gz
|
---|
107 | cd xlrd-$xlrd_version
|
---|
108 | python setup.py install
|
---|
109 | cd ..
|
---|
110 |
|
---|
111 | #########
|
---|
112 | # Web2Py
|
---|
113 | #########
|
---|
114 | apt-get -y install libodbc1
|
---|
115 | # Install Web2Py
|
---|
116 | # Add system user
|
---|
117 | adduser --system --disabled-password web2py
|
---|
118 | addgroup web2py
|
---|
119 | cd /home
|
---|
120 | # Delete old web2py version
|
---|
121 | rm web2py_src.zip
|
---|
122 | # Load actual web2py version
|
---|
123 | wget --no-check-certificate http://www.web2py.com/examples/static/web2py_src.zip
|
---|
124 | unzip web2py_src.zip
|
---|
125 | ln -s /home/web2py ~
|
---|
126 | cp -f /home/web2py/handlers/wsgihandler.py /home/web2py
|
---|
127 |
|
---|
128 | # Define the routes configuration
|
---|
129 | cat << EOF > "/home/web2py/routes.py"
|
---|
130 | #!/usr/bin/python
|
---|
131 | default_application = 'eden'
|
---|
132 | default_controller = 'default'
|
---|
133 | default_function = 'index'
|
---|
134 | routes_onerror = [
|
---|
135 | ('eden/400', '!'),
|
---|
136 | ('eden/401', '!'),
|
---|
137 | ('eden/509', '!'),
|
---|
138 | ('eden/*', '/eden/errors/index'),
|
---|
139 | ('*/*', '/eden/errors/index'),
|
---|
140 | ]
|
---|
141 | EOF
|
---|
142 |
|
---|
143 | # Configure Matplotlib
|
---|
144 | mkdir /home/web2py/.matplotlib
|
---|
145 | chown web2py /home/web2py/.matplotlib
|
---|
146 | echo "os.environ['MPLCONFIGDIR'] = '/home/web2py/.matplotlib'" >> /home/web2py/wsgihandler.py
|
---|
147 | sed -i 's|TkAgg|Agg|' /etc/matplotlibrc
|
---|
148 |
|
---|
149 | ##############
|
---|
150 | # Sahana Eden
|
---|
151 | ##############
|
---|
152 | # Install Sahana Eden
|
---|
153 | cd web2py
|
---|
154 | cd applications
|
---|
155 | # @ToDo: Stable branch
|
---|
156 | git clone git://github.com/flavour/eden.git
|
---|
157 | # Fix permissions
|
---|
158 | chown web2py ~web2py
|
---|
159 | chown web2py ~web2py/applications/admin/cache
|
---|
160 | chown web2py ~web2py/applications/admin/cron
|
---|
161 | chown web2py ~web2py/applications/admin/databases
|
---|
162 | chown web2py ~web2py/applications/admin/errors
|
---|
163 | chown web2py ~web2py/applications/admin/sessions
|
---|
164 | chown web2py ~web2py/applications/eden
|
---|
165 | chown web2py ~web2py/applications/eden/cache
|
---|
166 | chown web2py ~web2py/applications/eden/cron
|
---|
167 | mkdir -p ~web2py/applications/eden/databases
|
---|
168 | chown web2py ~web2py/applications/eden/databases
|
---|
169 | mkdir -p ~web2py/applications/eden/errors
|
---|
170 | chown web2py ~web2py/applications/eden/errors
|
---|
171 | chown web2py ~web2py/applications/eden/models
|
---|
172 | mkdir -p ~web2py/applications/eden/sessions
|
---|
173 | chown web2py ~web2py/applications/eden/sessions
|
---|
174 | chown web2py ~web2py/applications/eden/static/fonts
|
---|
175 | chown web2py ~web2py/applications/eden/static/img/markers
|
---|
176 | mkdir -p ~web2py/applications/eden/static/cache/chart
|
---|
177 | chown web2py -R ~web2py/applications/eden/static/cache
|
---|
178 | mkdir -p ~web2py/applications/eden/uploads/gis_cache
|
---|
179 | mkdir -p ~web2py/applications/eden/uploads/images
|
---|
180 | mkdir -p ~web2py/applications/eden/uploads/tracks
|
---|
181 | chown web2py ~web2py/applications/eden/uploads
|
---|
182 | chown web2py ~web2py/applications/eden/uploads/gis_cache
|
---|
183 | chown web2py ~web2py/applications/eden/uploads/images
|
---|
184 | chown web2py ~web2py/applications/eden/uploads/tracks
|
---|
185 | ln -s /home/web2py/applications/eden /home/web2py
|
---|
186 | ln -s /home/web2py/applications/eden ~
|
---|
187 |
|
---|
188 | ## Add Scheduler config
|
---|
189 | cat << EOF > "/home/web2py/run_scheduler.py"
|
---|
190 | #!/usr/bin/env python
|
---|
191 | # -*- coding: utf-8 -*-
|
---|
192 |
|
---|
193 | import os
|
---|
194 | import sys
|
---|
195 |
|
---|
196 | if '__file__' in globals():
|
---|
197 | path = os.path.dirname(os.path.abspath(__file__))
|
---|
198 | os.chdir(path)
|
---|
199 | else:
|
---|
200 | path = os.getcwd() # Seems necessary for py2exe
|
---|
201 |
|
---|
202 | sys.path = [path]+[p for p in sys.path if not p==path]
|
---|
203 |
|
---|
204 | # import gluon.import_all ##### This should be uncommented for py2exe.py
|
---|
205 | import gluon.widget
|
---|
206 | from gluon.shell import run
|
---|
207 |
|
---|
208 | # Start Web2py Scheduler -- Note the app name is hardcoded!
|
---|
209 | if __name__ == '__main__':
|
---|
210 | run('eden',True,True,None,False,"from gluon import current; current._scheduler.loop()")
|
---|
211 | EOF
|
---|
212 |
|
---|
213 | #########
|
---|
214 | # Apache2 configuration
|
---|
215 | #########
|
---|
216 | apt-get -y install libapache2-mod-wsgi
|
---|
217 | a2enmod rewrite
|
---|
218 | a2enmod deflate
|
---|
219 | a2enmod headers
|
---|
220 | a2enmod expires
|
---|
221 | # Enable Basic Authentication for WebServices
|
---|
222 | sed -i 's|</IfModule>|WSGIPassAuthorization On|' /etc/apache2/mods-enabled/wsgi.conf
|
---|
223 | echo "</IfModule>" >> /etc/apache2/mods-enabled/wsgi.conf
|
---|
224 | # Prevent Memory leaks from killing servers
|
---|
225 | sed -i 's|MaxRequestsPerChild 0|MaxRequestsPerChild 300|' /etc/apache2/apache2.conf
|
---|
226 | # Tune for smaller RAM setups
|
---|
227 | sed -i 's|MinSpareServers 5|MinSpareServers 3|' /etc/apache2/apache2.conf
|
---|
228 | sed -i 's|MaxSpareServers 10|MaxSpareServers 6|' /etc/apache2/apache2.conf
|
---|
229 | # Activate apache root - disabled as default since debian 8!
|
---|
230 | sed -i 's|Require all denied|#Require all denied|' /etc/apache2/apache2.conf
|
---|
231 | apache2ctl restart
|
---|
232 | # Holding Page for Maintenance windows
|
---|
233 | cat << EOF > "/var/www/maintenance.html"
|
---|
234 | <html><body><h1>Site Maintenance</h1>Please try again later...</body></html>
|
---|
235 | EOF
|
---|
236 |
|
---|
237 | /etc/init.d/apache2 restart
|
---|
238 |
|
---|
239 | # -----------------------------------------------------------------------------
|
---|
240 | # Further apache2 web server configuration
|
---|
241 | # -----------------------------------------------------------------------------
|
---|
242 | echo "Setting up Web server"
|
---|
243 | # Disable default site
|
---|
244 | rm -f /etc/apache2/sites-enabled/000-default.conf
|
---|
245 | # Define VirtualHost for production site
|
---|
246 | cat << EOF > "/etc/apache2/sites-available/production$extension"
|
---|
247 | <VirtualHost *:80>
|
---|
248 | ServerName $hostname.$DOMAIN
|
---|
249 | ServerAdmin webmaster@$DOMAIN
|
---|
250 | DocumentRoot /home/web2py/applications
|
---|
251 | WSGIScriptAlias / /home/web2py/wsgihandler.py
|
---|
252 | ## Edit the process and the maximum-requests to reflect your RAM
|
---|
253 | WSGIDaemonProcess web2py user=web2py group=web2py home=/home/web2py processes=4 maximum-requests=100
|
---|
254 | RewriteEngine On
|
---|
255 | # Stop GoogleBot from slowing us down
|
---|
256 | RewriteRule .*robots\.txt$ /eden/static/robots.txt [L]
|
---|
257 | # extract desired cookie value from multiple-cookie HTTP header
|
---|
258 | #RewriteCond %{HTTP_COOKIE} registered=([^;]+)
|
---|
259 | # check that cookie value is correct
|
---|
260 | #RewriteCond %1 ^yes$
|
---|
261 | #RewriteRule ^/$ /eden/ [R,L]
|
---|
262 | #RewriteRule ^/$ /eden/static/index.html [R,L]
|
---|
263 | RewriteCond %{REQUEST_URI} !/phpmyadmin(.*)
|
---|
264 | RewriteCond %{REQUEST_URI} !/eden/(.*)
|
---|
265 | RewriteRule /(.*) /eden/$1 [R]
|
---|
266 | ### static files do not need WSGI
|
---|
267 | <LocationMatch "^(/[\w_]*/static/.*)">
|
---|
268 | Order Allow,Deny
|
---|
269 | Allow from all
|
---|
270 | SetOutputFilter DEFLATE
|
---|
271 | BrowserMatch ^Mozilla/4 gzip-only-text/html
|
---|
272 | BrowserMatch ^Mozilla/4\.0[678] no-gzip
|
---|
273 | BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
|
---|
274 | SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
|
---|
275 | Header append Vary User-Agent env=!dont-vary
|
---|
276 | ExpiresActive On
|
---|
277 | ExpiresByType text/html "access plus 1 day"
|
---|
278 | ExpiresByType text/javascript "access plus 1 week"
|
---|
279 | ExpiresByType text/css "access plus 2 weeks"
|
---|
280 | ExpiresByType image/ico "access plus 1 month"
|
---|
281 | ExpiresByType image/gif "access plus 1 month"
|
---|
282 | ExpiresByType image/jpeg "access plus 1 month"
|
---|
283 | ExpiresByType image/jpg "access plus 1 month"
|
---|
284 | ExpiresByType image/png "access plus 1 month"
|
---|
285 | ExpiresByType application/x-shockwave-flash "access plus 1 month"
|
---|
286 | </LocationMatch>
|
---|
287 | ### everything else goes over WSGI
|
---|
288 | <Location "/">
|
---|
289 | $GRANT
|
---|
290 | WSGIProcessGroup web2py
|
---|
291 | </Location>
|
---|
292 | ErrorLog /var/log/apache2/$hostname_error.log
|
---|
293 | LogLevel warn
|
---|
294 | CustomLog /var/log/apache2/$hostname_access.log combined
|
---|
295 | </VirtualHost>
|
---|
296 | EOF
|
---|
297 |
|
---|
298 | # Enable production site
|
---|
299 | a2ensite production
|
---|
300 | apache2ctl restart
|
---|
301 |
|
---|
302 | # Define maintenance site
|
---|
303 | cat << EOF > "/etc/apache2/sites-available/maintenance$extension"
|
---|
304 | <VirtualHost *:80>
|
---|
305 | ServerName $hostname.$DOMAIN
|
---|
306 | ServerAdmin webmaster@$DOMAIN
|
---|
307 | DocumentRoot /var/www
|
---|
308 | RewriteEngine On
|
---|
309 | RewriteRule ^/(.*) /maintenance.html
|
---|
310 | <Location "/">
|
---|
311 | $GRANT
|
---|
312 | </Location>
|
---|
313 | ErrorLog /var/log/apache2/maintenance_error.log
|
---|
314 | LogLevel warn
|
---|
315 | CustomLog /var/log/apache2/maintenance_access.log combined
|
---|
316 | </VirtualHost>
|
---|
317 | EOF
|
---|
318 |
|
---|
319 | ############
|
---|
320 | # PostgreSQL
|
---|
321 | ############
|
---|
322 | apt-get update
|
---|
323 | apt-get -y install postgresql-9.4 python-psycopg2 postgresql-9.4-postgis ptop
|
---|
324 |
|
---|
325 | # Tune PostgreSQL
|
---|
326 | cat << EOF >> "/etc/sysctl.conf"
|
---|
327 | ## Increase Shared Memory available for PostgreSQL
|
---|
328 | # 512Mb
|
---|
329 | kernel.shmmax = 279134208
|
---|
330 | # 1024Mb (may need more)
|
---|
331 | #kernel.shmmax = 552992768
|
---|
332 | kernel.shmall = 2097152
|
---|
333 | EOF
|
---|
334 | sysctl -w kernel.shmmax=279134208 # For 512 MB RAM
|
---|
335 | #sysctl -w kernel.shmmax=552992768 # For 1024 MB RAM
|
---|
336 | sysctl -w kernel.shmall=2097152
|
---|
337 |
|
---|
338 | sed -i 's|#track_counts = on|track_counts = on|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
339 | sed -i 's|#autovacuum = on|autovacuum = on|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
340 | # 512Mb RAM:
|
---|
341 | sed -i 's|shared_buffers = 28MB|shared_buffers = 56MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
342 | sed -i 's|#effective_cache_size = 128MB|effective_cache_size = 256MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
343 | sed -i 's|#work_mem = 1MB|work_mem = 2MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
344 | # If 1Gb+ RAM, activate post-install via pg1024 script
|
---|
345 |
|
---|
346 | #####################
|
---|
347 | # Adopted management scripts from old cherokee installation
|
---|
348 | #####################
|
---|
349 | cat << EOF > "/usr/local/bin/maintenance"
|
---|
350 | #!/bin/sh
|
---|
351 | # Script to activate/deactivate the maintenance site
|
---|
352 | # Can provide the option 'off' to disable the maintenance site
|
---|
353 | if [ "\$1" != "off" ]; then
|
---|
354 | # Stop the Scheduler
|
---|
355 | killall python
|
---|
356 | # Deactivate the Production Site
|
---|
357 | a2dissite production
|
---|
358 | # Activate the Maintenance Site
|
---|
359 | a2ensite maintenance
|
---|
360 | else
|
---|
361 | # Deactivate the Maintenance Site
|
---|
362 | a2dissite maintenance
|
---|
363 | # Activate the Production Site
|
---|
364 | a2ensite production
|
---|
365 | # Start the Scheduler
|
---|
366 | cd ~web2py && sudo -H -u web2py nohup python web2py.py -K eden -Q >/dev/null 2>&1 &
|
---|
367 | fi
|
---|
368 | apache2ctl restart
|
---|
369 | EOF
|
---|
370 | chmod +x /usr/local/bin/maintenance
|
---|
371 | #####################
|
---|
372 | cat << EOF > "/usr/local/bin/backup"
|
---|
373 | #!/bin/sh
|
---|
374 | mkdir /var/backups/eden
|
---|
375 | chown postgres /var/backups/eden
|
---|
376 | NOW=\$(date +"%Y-%m-%d")
|
---|
377 | su -c - postgres "pg_dump -c sahana > /var/backups/eden/sahana-\$NOW.sql"
|
---|
378 | #su -c - postgres "pg_dump -Fc gis > /var/backups/eden/gis.dmp"
|
---|
379 | OLD=\$(date --date='7 day ago' +"%Y-%m-%d")
|
---|
380 | rm -f /var/backups/eden/sahana-\$OLD.sql
|
---|
381 | mkdir /var/backups/eden/uploads
|
---|
382 | tar -cf /var/backups/eden/uploads/uploadsprod-\$NOW.tar -C /home/web2py/applications/eden ./uploads
|
---|
383 | bzip2 /var/backups/eden/uploads/uploadsprod-\$NOW.tar
|
---|
384 | rm -f /var/backups/eden/uploads/uploadsprod-\$OLD.tar.bz2
|
---|
385 | EOF
|
---|
386 | chmod +x /usr/local/bin/backup
|
---|
387 | #####################
|
---|
388 | cat << EOF > "/usr/local/bin/compile"
|
---|
389 | #!/bin/bash
|
---|
390 | /etc/init.d/apache2 stop
|
---|
391 | cd ~web2py
|
---|
392 | python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
|
---|
393 | /etc/init.d/apache2 start
|
---|
394 | EOF
|
---|
395 | chmod +x /usr/local/bin/compile
|
---|
396 | #####################
|
---|
397 | cat << EOF > "/usr/local/bin/pull"
|
---|
398 | #!/bin/sh
|
---|
399 | /etc/init.d/apache2 stop
|
---|
400 | cd ~web2py/applications/eden
|
---|
401 | sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
|
---|
402 | git reset --hard HEAD
|
---|
403 | git pull
|
---|
404 | rm -rf compiled
|
---|
405 | cd ~web2py
|
---|
406 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
---|
407 | cd ~web2py/applications/eden
|
---|
408 | sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
|
---|
409 | cd ~web2py
|
---|
410 | python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
|
---|
411 | /etc/init.d/apache2 start
|
---|
412 | EOF
|
---|
413 | chmod +x /usr/local/bin/pull
|
---|
414 | #####################
|
---|
415 | cat << EOF > "/usr/local/bin/migrate"
|
---|
416 | #!/bin/sh
|
---|
417 | /etc/init.d/apache2 stop
|
---|
418 | cd ~web2py/applications/eden
|
---|
419 | sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
|
---|
420 | rm -rf compiled
|
---|
421 | cd ~web2py
|
---|
422 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
---|
423 | cd ~web2py/applications/eden
|
---|
424 | sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
|
---|
425 | cd ~web2py
|
---|
426 | python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
|
---|
427 | /etc/init.d/apache2 start
|
---|
428 | EOF
|
---|
429 | chmod +x /usr/local/bin/migrate
|
---|
430 | #####################
|
---|
431 | cat << EOF > "/usr/local/bin/revert"
|
---|
432 | #!/bin/sh
|
---|
433 | git reset --hard HEAD
|
---|
434 | EOF
|
---|
435 | chmod +x /usr/local/bin/revert
|
---|
436 | cat << EOF > "/usr/local/bin/w2p"
|
---|
437 | #!/bin/sh
|
---|
438 | cd ~web2py
|
---|
439 | python web2py.py -S eden -M
|
---|
440 | EOF
|
---|
441 | chmod +x /usr/local/bin/w2p
|
---|
442 | #####################
|
---|
443 | cat << EOF2 > "/usr/local/bin/clean"
|
---|
444 | #!/bin/sh
|
---|
445 | /etc/init.d/apache2 stop
|
---|
446 | cd ~web2py/applications/eden
|
---|
447 | rm -rf databases/*
|
---|
448 | rm -f errors/*
|
---|
449 | rm -rf sessions/*
|
---|
450 | rm -rf uploads/*
|
---|
451 | pkill -f "postgres: $database_user $database_name"
|
---|
452 | echo "SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$database_name';" > /tmp/delete_current_connections.sql
|
---|
453 | su - postgres -c "psql -q -p $database_port -f /tmp/delete_current_connections.sql"
|
---|
454 | su - postgres -c "dropdb -p $database_port $database_name"
|
---|
455 | echo "database dropped"
|
---|
456 | sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' models/000_config.py
|
---|
457 | sed -i 's/settings.base.prepopulate = 0/#settings.base.prepopulate = 0/g' models/000_config.py
|
---|
458 | rm -rf compiled
|
---|
459 | su - postgres -c "createdb -O $database_user -p $database_port -E UTF8 $database_name -T template0"
|
---|
460 | #su -c - postgres "createlang plpgsql -d sahana"
|
---|
461 | su - postgres -c "psql -q -p $database_port -d $database_name -f /usr/share/postgresql/9.4/contrib/postgis-2.1/postgis.sql"
|
---|
462 | su - postgres -c "psql -q -p $database_port -d $database_name -f /usr/share/postgresql/9.4/contrib/postgis-2.1/spatial_ref_sys.sql"
|
---|
463 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on geometry_columns to $database_user;'"
|
---|
464 | #maybe new to postgis 2.x
|
---|
465 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on geography_columns to $database_user;'"
|
---|
466 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'grant all on spatial_ref_sys to $database_user;'"
|
---|
467 | su - postgres -c "psql -q -p $database_port -d $database_name -c 'ALTER DATABASE $database_name OWNER TO $database_user;'"
|
---|
468 | cd ~web2py
|
---|
469 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py
|
---|
470 | cd ~web2py/applications/eden
|
---|
471 | sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' models/000_config.py
|
---|
472 | sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/g' models/000_config.py
|
---|
473 | cd ~web2py
|
---|
474 | python web2py.py -S eden -M -R applications/eden/static/scripts/tools/compile.py
|
---|
475 | /etc/init.d/apache2 start
|
---|
476 | #sudo -H -u web2py python web2py.py -S eden -M -R /home/data/import.py
|
---|
477 | EOF2
|
---|
478 | chmod +x /usr/local/bin/clean
|
---|
479 | #####################
|
---|
480 | cat << EOF > "/usr/local/bin/pg1024"
|
---|
481 | #!/bin/sh
|
---|
482 | sed -i 's|kernel.shmmax = 279134208|#kernel.shmmax = 279134208|' /etc/sysctl.conf
|
---|
483 | sed -i 's|#kernel.shmmax = 552992768|kernel.shmmax = 552992768|' /etc/sysctl.conf
|
---|
484 | sysctl -w kernel.shmmax=552992768
|
---|
485 | sed -i 's|shared_buffers = 56MB|shared_buffers = 160MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
486 | sed -i 's|effective_cache_size = 256MB|effective_cache_size = 512MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
487 | sed -i 's|work_mem = 2MB|work_mem = 4MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
488 | /etc/init.d/postgresql restart
|
---|
489 | EOF
|
---|
490 | chmod +x /usr/local/bin/pg1024
|
---|
491 | #####################
|
---|
492 | cat << EOF > "/usr/local/bin/pg512"
|
---|
493 | #!/bin/sh
|
---|
494 | sed -i 's|#kernel.shmmax = 279134208|kernel.shmmax = 279134208|' /etc/sysctl.conf
|
---|
495 | sed -i 's|kernel.shmmax = 552992768|#kernel.shmmax = 552992768|' /etc/sysctl.conf
|
---|
496 | sysctl -w kernel.shmmax=279134208
|
---|
497 | sed -i 's|shared_buffers = 160MB|shared_buffers = 56MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
498 | sed -i 's|effective_cache_size = 512MB|effective_cache_size = 256MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
499 | sed -i 's|work_mem = 4MB|work_mem = 2MB|' /etc/postgresql/9.4/main/postgresql.conf
|
---|
500 | /etc/init.d/postgresql restart
|
---|
501 | EOF
|
---|
502 | chmod +x /usr/local/bin/pg512
|
---|
503 | apt-get clean
|
---|
504 |
|
---|
505 | # END
|
---|