Going Live with Rails

March 27, 2009

Once an application gets to the production stage, people get all excited. The project is coming to fruition. Is it all over? No, its just the beginning. Ideally, you want your application to run trouble-free while you sit back and relax.

In this short article I will describe the steps that I go through when setting up a production environment. If you are interested in this subject and want a better guide please refer to deploying rails applications

Monit

This will keep everything running, I use this rather than god as it seems more stable and less memory hungry. I have used god a bit; the name also puts me off.

We still run ubuntu not cool enough for CentOS yet so.

aptitude install monit

Example monit config for rails app server with passenger.

Logrotate

You dont want massive logs slowing your app down after its been running 6 months, remember to configure this as it is often overlooked.

Passenger

Passenger or mod_rails is in active development and is used by a lot of the big ruby on rails companies and on the big sites. Deployment of production level apps used to be about packs of mongrels and frontend lightweight webservers. No longer.

Capistrano-ext

Deployment with capistrano is standard within the community, with the capistrano-ext gem you can run multistage deployments.

So

cap production deploy

Will deploy to production.

A list of my capistrano bash aliases are as follows. I find them very useful.

alias cpd="cap deploy"
alias cpdm="cap deploy:migrations"
alias cpsd="cap staging deploy"
alias cpsdm="cap staging deploy:migrations"
alias cppd="cap production deploy"
alias cppdm="cap production deploy:migrations"
alias cptd="cap testing deploy"
alias cptdm="cap testing deploy:migrations"

Backups

You need to be covered if something goes wrong. You need to backup static assets and database. I will not go into this here. Ideally, backup to an offsite location. eg. Amazon S3.

Exception notification

ake sure you have the exception notification plugin on the go, so you get emails when things break.

New Relic

The new relic performance monitoring service is great for keeping an eye on things within your production application. And there is a free version!

Version Control

Create a production branch in your version control and deploy from that. Then as you work for bugfixes and new features on master you then merge with the production branch for deployment.

eg.

To merge master with production.

git checkout production
git merge master

You can then also do critical changes to the production branch. And to get this back into master.

git checkout master
git merge production

Thats all for now. Any comments?