-
Notifications
You must be signed in to change notification settings - Fork 64
Deployment
- A computer with:
- Ubuntu 14.04 (also works with Ubuntu 12.04)
- Internet connection
We will begin by ensuring our default user, from now on {username}, has root permission by adding her to the sudoers list:
sudo adduser {username} sudo
You will be prompted for the root password.
Next, we will ensure Ubuntu packages are updated to the latest version. For that purpose we will update the package database and the global system:
sudo apt-get update; sudo apt-get dist-upgrade
To ensure a sane fallback locale, execute the following commands:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
sudo update-locale LC_ALL="en_US.utf-8"
The following packages are needed dependencies for our environment, and can be installed by executing:
sudo apt-get install git-core libxml2-dev nodejs libxslt1-dev libmagickcore-dev libmagickwand-dev\
libmysqlclient-dev libsqlite3-dev imagemagick libpq-dev make apache2-threaded-dev apache2-mpm-worker\
libcurl4-openssl-dev
First, we'll import the ruby repo gpg key:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
Next, we'll install a local ruby version 2.2.1 by rvm method
curl -L https://get.rvm.io | bash -s stable --ruby=2.2.0 --autolibs=enable --auto-dotfiles
source /home/{username}/.rvm/scripts/rvm
echo 'gem: --no-rdoc --no-ri' >> ~/.gemrc
gem install bundler -v "=1.8.0"
echo "export rvmsudo_secure_path=1">> /home/{username}/.bashrc
The sphinx search engine installation is as simple as typing:
sudo apt-get install sphinxsearch
ViSH will use the postfix mail agent, so we'll start by installing it:
sudo apt-get install postfix
At the configuration prompt, we'll leave the default selection "Internet Site"
Next, in case sendmail is installed, we will disable it by executing the following commands:
sudo service sendmail stop
sudo update-rc.d -f sendmail remove
sudo postfix start
Finally, we'll test the mail system by sending a test message and ensuring it is received
sudo apt-get install mailutils
echo "This is the message body" | mail -s "This is the subject" {test_mail_account_user@test_mail_account_domain}
ViSH will use postgres as the default sql database. To install it:
sudo apt-get install postgresql postgresql-contrib
To assign a password to the postgres user:
sudo -u postgres psql postgres
posgres#> ALTER USER postgres with password '{your_db_password}';
posgres#> \q
To create the vish_production db:
sudo -u postgres createdb vish_production
To use the passenger app server for ruby, we'll install and configure it with the following commands:
gem install rack -v=1.6.4
gem install passenger -v=4.0.59
passenger-install-apache2-module
sudo a2enmod passenger
sudo service apache2 restart
We will create the folder structure where our production environment will reside by executing the following bash commands:
sudo mkdir /u
sudo chown {username}:root /u
mkdir /u/apps
mkdir /u/apps/vish
mkdir /u/apps/vish/shared/
mkdir /u/apps/vish/shared/log
mkdir /u/apps/vish/shared/pids
mkdir /u/apps/vish/shared/system
mkdir /u/apps/vish/shared/system/actors
mkdir /u/apps/vish/shared/system/pdfexes
mkdir /u/apps/vish/shared/system/tmp
mkdir /u/apps/vish/shared/system/pdfexes/attaches
chmod -R 777 /u/apps/vish/shared/system/
mkdir /u/apps/vish/shared/scripts
mkdir /u/apps/vish/shared/sitemap
mkdir /u/apps/vish/shared/documents
With the following commands, we will create the needed document storage folder structure:
mkdir /u/apps/vish/shared/documents/code
mkdir /u/apps/vish/shared/documents/documents
mkdir /u/apps/vish/shared/documents/videos
mkdir /u/apps/vish/shared/documents/activity_objects
mkdir /u/apps/vish/shared/documents/pictures
mkdir /u/apps/vish/shared/documents/audios
mkdir /u/apps/vish/shared/documents/webapps
mkdir /u/apps/vish/shared/documents/zipfiles
mkdir /u/apps/vish/shared/documents/swfs
mkdir /u/apps/vish/shared/documents/scormfiles
mkdir /u/apps/vish/shared/documents/officedocs
sudo chown www-data:www-data /u/apps/vish/shared/documents/*
Next, we'll download the source code from git into /u/apps/vish by executing the following commands:
cd /u/apps/vish
git clone https://github.com/ging/vish.git current
We will create the database file in /u/apps/vish/shared/database.yml , which will include the settings for accessing the postgre database previously configured.
production:
adapter: postgresql
database: vish_production
encoding: utf8
host: localhost
username: postgres
password: {your_db_password}
To allow remote access to our server, we'll remove the deny all directives in /etc/apache2/apache2.conf by removing the following lines:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
By executing the following two commands, we'll enable the needed Apache mods:
sudo a2enmod expires
sudo a2enmod headers
To install the required apache mod x-sendfile:
wget https://raw.githubusercontent.com/nmaier/mod_xsendfile/master/mod_xsendfile.c
sudo apt-get install apache2-dev
sudo apxs -cia mod_xsendfile.c
sudo service apache2 restart
Here we'll set up the production environment by editing several setting files
We can base our baseline configuration in the provided application_config.
cp /u/apps/vish/current/config/application_config.yml.example /u/apps/vish/shared/application_config.yml
Edit the /u/apps/vish/shared/application_config.yml file to include the following settings. For more information on the behaviour of these settings, please check Setting up a ViSH instance
production:
domain: "vishub.org"
test_domain: false
code_path: "/home/isabel/vish-shared/documents/code"
no_reply_mail: "[email protected]"
main_mail: "[email protected]"
models:
available: ["Excursion","Resource","Category","Event","Workshop"]
resources: ["Document","Webapp","Scormfile","Link","Embed", "Writing"]
home: ["Excursion"]
catalogue: ["Excursion"]
services: ["ARS","Catalogue","Competitions2013","ASearch","MediaConversion"]
languages: ["en", "es", "de", "nl", "hu", "fr"]
register_policy: "REGISTER_ONLY"
advanced_search:
instances: ["http://vishub.org"]
mail:
type: "SMTP"
credentials:
address: "smtp.mandrillapp.com"
port: 587
domain: "your_domain.com"
authentication: "login" #or can use "plain"
username: "{your_username}"
password: "your_password"
enable_starttls_auto: true
Next, to customize the administrator notifications in case of exceptions, we'll edit the file /u/apps/vish/shared/exception_notification.rb, inserting or modifying the following content as needed:
Vish::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[ViSH] ",
:sender_address => %{"Error Notifier" <{[email protected]}>},
:exception_recipients => %w{{[email protected]}}
}
To configure our site server, we need to create the file /etc/apache2/sites-available/vishub.conf, and add to it the following content:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName XXXX.org
ServerAlias www.XXXX.org
ServerAlias m.XXXX.org
DocumentRoot /u/apps/vish/current/public/
<Directory /u/apps/vish/current/public/>
AllowOverride all
Options -MultiViews
Header set Accept-Ranges bytes
AllowOverride FileInfo
XSendFile On
XSendFilePath /u/apps/vish/releases/
</Directory>
<FilesMatch "\.(gif|jpe?g|png|mp4|webm|ogg|mp3|wav|flv|svg|ttf|otf|eot|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
# gzip html, css and js
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript application/javascript image/svg+xml
# far future expires headers
<FilesMatch "\.(ico|svg|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header unset Last-Modified
Header unset ETag
FileETag None
#RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault "access plus 1 year"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
PassengerPoolIdleTime 500
PassengerMaxPoolSize 8
PassengerMinInstances 4
</VirtualHost>
PassengerPreStart http://XXXX.org
Next, we will create symbolic links to the apache configuration files:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo ln -s /etc/apache2/sites-available/vishub.conf /etc/apache2/sites-enabled/vishub.conf
Now we will create symbolic links to the configuration files located in the shared folder.
ln -s /u/apps/vish/shared/application_config.yml /u/apps/vish/current/config/application_config.yml
ln -s /u/apps/vish/shared/database.yml /u/apps/vish/current/config/database.yml
ln -s /u/apps/vish/shared/exception_notification.rb /u/apps/vish/current/config/initializers/exception_notification.rb
There are separate instructions to install the media conversion system, which can be found here: Set up the Media Conversion service
To enable automatic startup for ViSH and sphinx services we'll follow the next steps...
We'll edit the file /etc/init.d/vish, adding the following content:
#! /bin/sh
### BEGIN INIT INFO
# Provides: vish
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start services for vish
### END INIT INFO
case $1 in
start|restart|force-reload)
/bin/bash -c "god -c /u/apps/vish/current/config/resque.god"
sudo -i -u YOUR_USERNAME bash -c "cd /u/apps/vish/current ; bundle exec rake ts:rebuild RAILS_ENV=production"
/bin/chmod g+rw /u/apps/vish/current/log/searchd*
/bin/chown YOUR_USERNAME.www-data /u/apps/vish/current/log/searchd*
;;
stop)
;;
status)
exit 0
;;
*)
echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
And give it exec rights with:
sudo chmod 755 /etc/init.d/vish
Finally we add the file to the startup process by executing:
sudo update-rc.d vish start 20 2 3 4 5 .
We automate the sphinx service startup by editing /etc/rc.local and adding the following line before exit 0
:
/usr/bin/searchd --pidfile --config /u/apps/vish/current/config/production.sphinx.conf
To finish the installation:
sudo chown -R {username}:www-data /u/apps/vish/shared/log/
sudo chmod 777 /u/apps/vish/shared/log/searchd.production.pid
bundle install --without development test
bundle exec rake db:install RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
To end the deployment we automate the timed tasks by editing the file in extras/cron/vish_rvm and copying it to /etc/cron.d/vish_rvm
sudo cp extras/cron/vish_rvm /etc/cron.d/.
cp /u/apps/vish/current/lib/scripts/check_daemon.sh /u/apps/vish/shared/scripts/.
Next we edit /etc/cron.d/vish to enter our {username} Then we edit the crontab file with
sudo crontab -e
And add the following line
09 * * * * export CAP_USER=username && /u/apps/vish/shared/scripts/check_daemon.sh > /tmp/test.txt 2>&1
Finally, for ease of use, we create the following symbolic link in our home directory:
cd /home/{username}
ln -s /u/apps/vish/current/ vish
You can find how to do this here: Configure Logrotate
The next steps are taken in a development machine. To install a development environment you can read the following instructions: ViSH Installation.
In the development machine, we'll customize the production environment based on our deployment file in vish/config/deploy/{environment}.yml. The vish/config/deploy/example.yml contains all the information that should be filled in:
message: "Deploying to Example!"
repository: [email protected]:ging/vish.git
server_url: 127.0.0.1 #put here the server URL (e.g. example.com)
username: ubuntu
keys: /home/username/.ssh/ssh-keypair #empty or remove this line if you don't have any key
branch: master
with_workers: false #true if this instance has workers, i.e. video and audio conversion to HTML5 (Media Conversion service)
Finally, we can deploy our ViSH application by executing:
bundle exec cap deploy DEPLOY={environment}
This way, if we define a production environment in vish/config/deploy/production.yml, we can deploy it with the following command:
bundle exec cap deploy DEPLOY=production
This way, we can specify several production environments for the same application in our development machine.