Migrating Acemoney onto a different server with nginx+passenger
Acemoney is a hosted application built by us i.e. Josh Software. Currently, its hosted on a linode with nginx+thin configured. The problem here is that there are 3 thin servers which consume humongous ‘stagnant’ memory. We have decided to migrate to nginx+passenger so that we an control in greater detail the number of instances, the memory and the performance.
Some things in the post are specific to Josh Software and its client. Overall, this should give a good clean idea about migrating to passenger.
1. Checkout from the branch from the respository (the 2.3.4 version)
2. Ensure Rails 2.3.4 is installed
3. Edit the nginx configuration. /opt/nginx/conf/servers/acemoney.in
listen 80; server_name acemoney.in; passenger_enabled on; root <path-to-deployment>/acemoney/public; }
4. Restart Nginx. In case you get an error — something like:
2009/10/27 16:02:07 [error] 32685#0: *9 directory index of "/home/gautam/deployment/acemoney/public/" is forbidden, client: 184.108.40.206, server: acemoney.in, request: "GET / HTTP/1.1", host: "acemoney.in"
Check syntax in the conf file (I had forgotten a ‘;’) OR check permissions of the root directory to see if you have given r+x permissions
5. The current gem setup was:
$:/opt/nginx/conf/servers$ sudo gem search *** LOCAL GEMS *** abstract (1.0.0) actionmailer (2.3.4, 2.3.3, 2.2.2, 2.1.2) actionpack (2.3.4, 2.3.3, 2.2.2, 2.1.2) activerecord (2.3.4, 2.3.3, 2.2.2, 2.1.2) activeresource (2.3.4, 2.3.3, 2.2.2, 2.1.2) activesupport (2.3.4, 2.3.3, 2.2.2, 2.1.2) capistrano (2.5.5) cgi_multipart_eof_fix (2.5.0) chronic (0.2.3) contacts (1.0.13) daemons (1.0.10) engineyard-eycap (0.4.7) erubis (2.6.4) eventmachine (0.12.6) fastthread (1.0.7) gem_plugin (0.2.3) heywatch (0.0.1) highline (1.5.0) hoe (1.12.2) json (1.1.6) memcache-client (1.7.2) mislav-will_paginate (2.3.10) mongrel (1.1.5) mongrel_cluster (1.0.5) mysql (2.7) net-scp (1.0.2) net-sftp (2.0.2) net-ssh (2.0.11) net-ssh-gateway (1.0.1) packet (0.1.15) passenger (2.2.5) rack (1.0.0, 0.9.1) rails (2.3.4, 2.3.3, 2.2.2, 2.1.2) rake (0.8.4) RedCloth (4.1.9) right_aws (1.10.0) right_http_connection (1.2.4) rubyforge (1.0.3) rubyist-aasm (2.0.5) thin (1.0.0) tidy (1.1.2) xml-simple (1.0.12)
So, I had to add the following gems:
$ sudo gem install acts_as_reportable
This added the following dependencies:
Successfully installed fastercsv-1.2.3
Successfully installed archive-tar-minitar-0.5.2
Successfully installed color-1.4.0
Successfully installed transaction-simple-1.4.0
Successfully installed pdf-writer-1.1.8
Successfully installed ruport-1.6.1
Successfully installed acts_as_reportable-1.1.1
Successfully installed json_pure-1.1.9
Successfully installed rubyforge-2.0.3
Successfully installed rake-0.8.7
$ sudo gem install prawn $ sudo gem install ferret $ sudo gem install acts_as_ferret
6. Then I got the latest database dump from Acemoney server and configured the database locally. Edit the config/database.yml and the following:
production: adapter: mysql user: acemoney password: <password> host: localhost
Created a new user in mysql and granted ALL permissions to acemoney database
mysql> grant all on acemoney.* to 'acemoney'@'localhost' identified by '<password>'
Then create the database and dump the contents from the backup
$ RAILS_ENV=production rake db:create $ mysql -uacemoney acemoney -p < <backupfile>
Start the ferret_server
$ ./script/ferret_server -eproduction start
Build the index:
$ RAILS_ENV=production rake ace:rebuildFerretIndex
NOW, we are good to go. Make some local changes in /etc/hosts file on your machine to point acemoney.in to the linode IP address. Then http://acemoney.in should take you to the hosted application on nginx+passenger.