| 4 | |
| 5 | The simplest way to install is using our attached installation scripts. |
| 6 | |
| 7 | 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. |
| 8 | |
| 9 | Before Imaging: install-eden-apache-mysql.sh |
| 10 | {{{ |
| 11 | #!/bin/sh |
| 12 | |
| 13 | # Script to turn a generic Debian Squeeze box into an Eden server |
| 14 | # with Apache & MySQL |
| 15 | |
| 16 | # Update system |
| 17 | apt-get update |
| 18 | apt-get upgrade -y |
| 19 | |
| 20 | # Install Admin Tools |
| 21 | apt-get install -y unzip psmisc mlocate telnet lrzsz vim elinks-lite rcconf htop sudo |
| 22 | # Email |
| 23 | apt-get -y install exim4-config exim4-daemon-light |
| 24 | |
| 25 | ######## |
| 26 | # MySQL |
| 27 | ######## |
| 28 | apt-get -y install mysql-server python-mysqldb phpmyadmin mytop |
| 29 | |
| 30 | ######### |
| 31 | # Apache |
| 32 | ######### |
| 33 | apt-get -y install libapache2-mod-wsgi |
| 34 | a2enmod rewrite |
| 35 | a2enmod deflate |
| 36 | a2enmod headers |
| 37 | a2enmod expires |
| 38 | |
| 39 | # Enable Basic Authentication for WebServices |
| 40 | sed -i 's|</IfModule>|WSGIPassAuthorization On|' /etc/apache2/mods-enabled/wsgi.conf |
| 41 | echo "</IfModule>" >> /etc/apache2/mods-enabled/wsgi.conf |
| 42 | |
| 43 | apache2ctl restart |
| 44 | |
| 45 | # Holding Page for Maintenance windows |
| 46 | cat << EOF > "/var/www/maintenance.html" |
| 47 | <html><body><h1>Site Maintenance</h1>Please try again later...</body></html> |
| 48 | EOF |
| 49 | |
| 50 | ######### |
| 51 | # Python |
| 52 | ######### |
| 53 | # Install Libraries |
| 54 | apt-get -y install libgeos-c1 |
| 55 | |
| 56 | # Install Python 2.6 |
| 57 | apt-get -y install python2.6 python-dev ipython |
| 58 | apt-get -y install python-lxml python-setuptools python-shapely python-dateutil |
| 59 | apt-get -y install python-serial |
| 60 | apt-get -y install python-imaging python-reportlab |
| 61 | apt-get -y install python-xlwt python-xlrd |
| 62 | apt-get -y install bzr |
| 63 | |
| 64 | ######### |
| 65 | # Web2Py |
| 66 | ######### |
| 67 | # Install Web2Py |
| 68 | adduser --system --disabled-password web2py |
| 69 | addgroup web2py |
| 70 | cd /home |
| 71 | bzr branch lp:~mdipierro/web2py/devel web2py --use-existing-dir |
| 72 | ln -s /home/web2py ~ |
| 73 | cat << EOF > "/home/web2py/routes.py" |
| 74 | #!/usr/bin/python |
| 75 | default_application = 'eden' |
| 76 | default_controller = 'default' |
| 77 | default_function = 'index' |
| 78 | routes_onerror = [ |
| 79 | ('eden/400', '!'), |
| 80 | ('eden/401', '!'), |
| 81 | ('eden/*', '/eden/errors/index'), |
| 82 | ('*/*', '/eden/errors/index'), |
| 83 | ] |
| 84 | EOF |
| 85 | |
| 86 | ############## |
| 87 | # Sahana Eden |
| 88 | ############## |
| 89 | # Install Sahana Eden |
| 90 | cd web2py |
| 91 | cd applications |
| 92 | bzr branch lp:sahana-eden eden |
| 93 | # Fix permissions |
| 94 | chown web2py ~web2py |
| 95 | chown web2py ~web2py/applications/admin/cache |
| 96 | chown web2py ~web2py/applications/admin/cron |
| 97 | chown web2py ~web2py/applications/admin/databases |
| 98 | chown web2py ~web2py/applications/admin/errors |
| 99 | chown web2py ~web2py/applications/admin/sessions |
| 100 | chown web2py ~web2py/applications/eden |
| 101 | chown web2py ~web2py/applications/eden/cache |
| 102 | chown web2py ~web2py/applications/eden/cron |
| 103 | chown web2py ~web2py/applications/eden/databases |
| 104 | chown web2py ~web2py/applications/eden/errors |
| 105 | chown web2py ~web2py/applications/eden/models |
| 106 | chown web2py ~web2py/applications/eden/sessions |
| 107 | chown web2py ~web2py/applications/eden/static/img/markers |
| 108 | chown web2py ~web2py/applications/eden/uploads |
| 109 | mkdir -p ~web2py/applications/eden/uploads/gis_cache |
| 110 | mkdir -p ~web2py/applications/eden/uploads/images |
| 111 | mkdir -p ~web2py/applications/eden/uploads/tracks |
| 112 | chown web2py ~web2py/applications/eden/uploads/gis_cache |
| 113 | chown web2py ~web2py/applications/eden/uploads/images |
| 114 | chown web2py ~web2py/applications/eden/uploads/tracks |
| 115 | ln -s /home/web2py/applications/eden ~ |
| 116 | |
| 117 | ##################### |
| 118 | # Management scripts |
| 119 | ##################### |
| 120 | cat << EOF > "/usr/local/bin/backup" |
| 121 | #!/bin/sh |
| 122 | NOW=$(date +"%Y-%m-%d") |
| 123 | mysqldump sahana > /root/backup-$NOW.sql |
| 124 | OLD=$(date --date='7 day ago' +"%Y-%m-%d") |
| 125 | rm -f /root/backup-$OLD.sql |
| 126 | EOF |
| 127 | chmod +x /usr/local/bin/backup |
| 128 | |
| 129 | cat << EOF > "/usr/local/bin/compile" |
| 130 | #!/bin/sh |
| 131 | cd ~web2py |
| 132 | python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py |
| 133 | apache2ctl restart |
| 134 | EOF |
| 135 | chmod +x /usr/local/bin/compile |
| 136 | |
| 137 | cat << EOF > "/usr/local/bin/maintenance" |
| 138 | #!/bin/sh |
| 139 | if [ "" != "off" ] |
| 140 | then |
| 141 | a2dissite maintenance |
| 142 | a2ensite production |
| 143 | cd ~web2py && sudo -H -u web2py python web2py.py -K eden -Q >/dev/null 2>&1 & |
| 144 | else |
| 145 | killall -u web2py python |
| 146 | a2ensite maintenance |
| 147 | a2dissite production |
| 148 | fi |
| 149 | apache2ctl restart |
| 150 | EOF |
| 151 | chmod +x /usr/local/bin/maintenance |
| 152 | |
| 153 | cat << EOF > "/usr/local/bin/pull" |
| 154 | #!/bin/sh |
| 155 | cd ~web2py/applications/eden |
| 156 | sed -i 's/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g' models/000_config.py |
| 157 | bzr pull |
| 158 | /usr/local/bin/maintenance |
| 159 | rm -rf compiled |
| 160 | cd ~web2py |
| 161 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py |
| 162 | cd ~web2py/applications/eden |
| 163 | sed -i 's/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g' models/000_config.py |
| 164 | /usr/local/bin/compile |
| 165 | /usr/local/bin/maintenance off |
| 166 | EOF |
| 167 | chmod +x /usr/local/bin/pull |
| 168 | |
| 169 | # Change the value of prepopulate, if-necessary |
| 170 | cat << EOF > "/usr/local/bin/clean" |
| 171 | #!/bin/sh |
| 172 | /usr/local/bin/maintenance |
| 173 | cd ~web2py/applications/eden |
| 174 | rm -f databases/* |
| 175 | rm -f errors/* |
| 176 | rm -f sessions/* |
| 177 | rm -f uploads/* |
| 178 | sed -i 's/deployment_settings.base.migrate = False/deployment_settings.base.migrate = True/g' models/000_config.py |
| 179 | sed -i 's/deployment_settings.base.prepopulate = 0/deployment_settings.base.prepopulate = 1/g' models/000_config.py |
| 180 | rm -rf compiled |
| 181 | mysqladmin -f drop sahana |
| 182 | mysqladmin create sahana |
| 183 | cd ~web2py |
| 184 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py |
| 185 | cd ~web2py/applications/eden |
| 186 | sed -i 's/deployment_settings.base.migrate = True/deployment_settings.base.migrate = False/g' models/000_config.py |
| 187 | sed -i 's/deployment_settings.base.prepopulate = 1/deployment_settings.base.prepopulate = 0/g' models/000_config.py |
| 188 | /usr/local/bin/maintenance off |
| 189 | /usr/local/bin/compile |
| 190 | EOF |
| 191 | chmod +x /usr/local/bin/clean |
| 192 | |
| 193 | cat << EOF > "/usr/local/bin/w2p" |
| 194 | #!/bin/sh |
| 195 | cd ~web2py |
| 196 | python web2py.py -S eden -M |
| 197 | EOF |
| 198 | chmod +x /usr/local/bin/w2p |
| 199 | |
| 200 | # END |
| 201 | }}} |
| 202 | |
| 203 | After Imaging: configure-eden-apache-mysql.sh |
| 204 | {{{ |
| 205 | #!/bin/sh |
| 206 | |
| 207 | # Script to configure an Eden server |
| 208 | # - assumes that install-eden-apache-mysql.sh has been run |
| 209 | |
| 210 | BRANCH="~flavour/sahana-eden/trunk" |
| 211 | |
| 212 | if [ "$BRANCH" != "~flavour/sahana-eden/trunk" ]; then |
| 213 | echo "parent_location = http://bazaar.launchpad.net/$BRANCH" > /home/web2py/applications/eden/.bzr/branch/branch.conf |
| 214 | fi |
| 215 | |
| 216 | echo -e "What domain name should we use? : \c " |
| 217 | read DOMAIN |
| 218 | |
| 219 | echo -e "What is host name should we use? : \c " |
| 220 | read hostname |
| 221 | sitename=$hostname".$DOMAIN" |
| 222 | |
| 223 | echo -e "What is the current root MySQL password: \c " |
| 224 | read rootpw |
| 225 | |
| 226 | # @ToDo: Generate a random password |
| 227 | echo -e "What should be the MySQL password for user 'sahana': \c " |
| 228 | read password |
| 229 | |
| 230 | echo "Now reconfiguring system" |
| 231 | |
| 232 | cd /etc |
| 233 | filename="hosts" |
| 234 | sed -i "s|localdomain localhost|localdomain localhost $hostname|" $filename |
| 235 | |
| 236 | cd /etc |
| 237 | filename="hostname" |
| 238 | echo $hostname > $filename |
| 239 | |
| 240 | cd /etc |
| 241 | filename="mailname" |
| 242 | echo $sitename > $filename |
| 243 | |
| 244 | # Update system (in case run at a much later time than the install script) |
| 245 | apt-get update |
| 246 | apt-get upgrade -y |
| 247 | cd ~web2py |
| 248 | bzr pull |
| 249 | cd ~web2py/applications/eden |
| 250 | bzr pull |
| 251 | |
| 252 | # ----------------------------------------------------------------------------- |
| 253 | # MySQL Database |
| 254 | # ----------------------------------------------------------------------------- |
| 255 | echo "Setting up Database" |
| 256 | |
| 257 | # Allow root user to access database without entering password |
| 258 | cat << EOF > "/root/.my.cnf" |
| 259 | [client] |
| 260 | user=root |
| 261 | EOF |
| 262 | |
| 263 | echo "password='$rootpw'" >> "/root/.my.cnf" |
| 264 | |
| 265 | # Create database |
| 266 | mysqladmin create sahana |
| 267 | |
| 268 | # Create user for Sahana application |
| 269 | echo "CREATE USER 'sahana'@'localhost' IDENTIFIED BY '$password';" > "/tmp/mypass" |
| 270 | echo "GRANT ALL PRIVILEGES ON *.* TO 'sahana'@'localhost' WITH GRANT OPTION;" >> "/tmp/mypass" |
| 271 | mysql < /tmp/mypass |
| 272 | rm -f /tmp/mypass |
| 273 | |
| 274 | # Schedule backups for 02:01 daily |
| 275 | echo "1 2 * * * * root /usr/local/bin/backup" >> "/etc/crontab" |
| 276 | |
| 277 | # ----------------------------------------------------------------------------- |
| 278 | # Email |
| 279 | # ----------------------------------------------------------------------------- |
| 280 | echo configure for Internet mail delivery |
| 281 | dpkg-reconfigure exim4-config |
| 282 | |
| 283 | # ----------------------------------------------------------------------------- |
| 284 | # Sahana Eden |
| 285 | # ----------------------------------------------------------------------------- |
| 286 | echo "Setting up Sahana" |
| 287 | |
| 288 | # Copy Templates |
| 289 | cp ~web2py/applications/eden/deployment-templates/cron/crontab ~web2py/applications/eden/cron |
| 290 | cp ~web2py/applications/eden/deployment-templates/models/000_config.py ~web2py/applications/eden/models |
| 291 | |
| 292 | sed -i 's|EDITING_CONFIG_FILE = False|EDITING_CONFIG_FILE = True|' ~web2py/applications/eden/models/000_config.py |
| 293 | sed -i "s|akeytochange|$sitename$password|" ~web2py/applications/eden/models/000_config.py |
| 294 | sed -i "s|127.0.0.1:8000|$sitename|" ~web2py/applications/eden/models/000_config.py |
| 295 | sed -i 's|base.cdn = False|base.cdn = True|' ~web2py/applications/eden/models/000_config.py |
| 296 | |
| 297 | # Configure Database |
| 298 | sed -i 's|deployment_settings.database.db_type = "sqlite"|deployment_settings.database.db_type = "mysql"|' ~web2py/applications/eden/models/000_config.py |
| 299 | sed -i "s|deployment_settings.database.password = \"password\"|deployment_settings.database.password = \"$password\"|" ~web2py/applications/eden/models/000_config.py |
| 300 | |
| 301 | # Create the Tables & Populate with base data |
| 302 | sed -i 's|deployment_settings.base.prepopulate = 0|deployment_settings.base.prepopulate = 1|' ~web2py/applications/eden/models/000_config.py |
| 303 | sed -i 's|deployment_settings.base.migrate = False|deployment_settings.base.migrate = True|' ~web2py/applications/eden/models/000_config.py |
| 304 | cd ~web2py |
| 305 | sudo -H -u web2py python web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py |
| 306 | |
| 307 | # Configure for Production |
| 308 | sed -i 's|deployment_settings.base.prepopulate = 1|deployment_settings.base.prepopulate = 0|' ~web2py/applications/eden/models/000_config.py |
| 309 | sed -i 's|deployment_settings.base.migrate = True|deployment_settings.base.migrate = False|' ~web2py/applications/eden/models/000_config.py |
| 310 | cd ~web2py |
| 311 | sudo -H -u web2py python web2py.py -S eden -R applications/eden/static/scripts/tools/compile.py |
| 312 | |
| 313 | # Add Scheduler |
| 314 | sed -i 's|exit 0|cd ~web2py \&\& python web2py.py -K eden -Q >/dev/null 2>\&1 \&|' /etc/rc.local |
| 315 | echo "exit 0" >> /etc/rc.local |
| 316 | |
| 317 | #read -p "Press any key to Reboot..." |
| 318 | echo "Now rebooting.." |
| 319 | reboot |
| 320 | |
| 321 | # END |
| 322 | }}} |