13 Sep 2007

Deploying rails application with pound as a Balancer

RubyonRails, Technology, deployment, hosting, mongrel_cluster, pound, rails, web development posted by Akhil Bansal

Now a days Apache + mod_proxy + mongrel_clusters, Lighttpd + Mongrel cluster and Nginx + mongrel cluster are well known for deploying rails applications.

You can also deploy your rails application with pound(a reverse proxy, load balancer and HTTPS front-end for Web server).

First you need to setup mongrel_clusters for your rails application by issuing ” mongrel_rails cluster::configure -e production -p 8000 -a 127.0.0.1 -N 3 -c ./ ” inside the rails application root directory(on client machine). This will create mongrel_cluster.yml in config directory. You can change parameters in this command, as -p 8000 specifies that mongrel instances will start up on port number starting 8000, -a 127.0.0.1 specifies that mongrel instances will listen to the localhost, -N specifies the number of mongrel instances and -c specifies the rails root directory.

Now you need to install pound(if not installed) by issuing following commands(as root):

  • cd /opt/src
  • wget http://www.apsis.ch/pound/Pound-2.3.2.tgz
  • tar xzpf Pound-2.1.6.tgz
  • cd Pound-2.1.6
  • ./configure
  • make
  • make install

This will install pound in /usr/local/sbin/pound. In order to proceed further we need to create pound.cfg(pound configuration file) in /etc/pound/pound.cfg . Below is the content of pound.cfg:

Start mongrel cluster by issuing mongrel_rails cluster::start in you app root directory, start pound by /usr/local/sbin/pound -f /etc/pound/pound.cfg , now you are done. Pound is listening the port 80 and redirect all requests to mongrel instances running on 8000, 8001, 8002.

* Please Note that we have configured pound at port 80, if port 80 is being used by apache or any other application pound will not start. You need to stop any service using port 80, if it is apache then stop apache, change line ‘Listen 80′ to “Listen 8080″ and start apache.

In a specific case, when apache is running at some port (let say 8080), you may want to use apache to serve static content of your application, in order to reduce some load from mongrels. In that case use the following:

This will redirect all requests for image, stylesheets, javascripts, flash to apache. Now we need to configure apache to serve those static content. Just add a virtualhost for that:

Its all done. All requests for dynamic content at port 80 will be redirect to mongrel running at 8000, 8001, 8001 and requests for static content will be served by apache running at port 8080.

13 Sep 2007

Acts_as_solr: Starting solr server on windows

RubyonRails, Technology, acts_as_solr, rails, rails plugins, ruby, solr posted by Akhil Bansal

I was using acts_as_searchable for one of my project, which uses Hyperestraier in background. Yesterday I decided to use acts_as_solr which uses solr(based on Lucene Java search library). I did all written in its Manual/Readme, but when I issued

to start the solr server, it threw a heart breaking “Bad file descriptor” error, although acts_as_solr was working fine on one of my colleague’s linux machine.

I started digging around this and found that there is an issue in rake task that starts the solr server. Actually the problem was this rake task uses ‘fork’ which is not available on windows, also it only handles ‘ECONNREFUSED’ exception which is actually “Connection Refused” error raised by ruby on linux. But in windown it throws ‘EBADF’ which is “Bad file descriptor” error raised by ruby on windows.

So below is the hack for that:

Just add this to vendor/plugins/acts_as_solr/lib/taks/solr.rake, and start solr server on windows by issuing

30 Aug 2007

Customizing CruiseControl build for RSpec

CruiseControl, RubyonRails, Technology, Tools, rails, ruby, web development posted by Akhil Bansal

Yesterday I posted about CruiseControl for Rails projects. It was working fine with all my rails projects using traditional test cases, But today I faced a problem with a project using RSpec. Actually, By default CruiseControl follows the following step to build:

  1. rake db:test:purge
  2. rake db:migrate
  3. rake test

This default was not working with my last project As I was using RSpec for my project. I found that we can overwrite default way of building by creating a rake task named cruise in our project. Means by building CruiseControl will run your custom rake task only, so you have to take care of all other things i.e. migrate etc.

Hence I created following rake task in RAILS_ROOT/lib/tasks/custom_cc.rake

and it worked for my rails project using RSpec.

29 Aug 2007

CruiseControl.rb: A Continuous integration tool for your rails projects.

CruiseControl, RubyonRails, Technology, Tools, rails, ruby posted by Akhil Bansal

We at vinsol recently started using CruiseControl for our rails project. CruiseControl is a continuous integration tool. Which keeps an eye on you code repository and runs all test cases (or the command you specify) whenever new version of code is found, it also sends a mail to all members specified when testcases fails with details. I found this tool very helpful and customizable. If you don’t use CruiseControl , I suggest you to give it a try.

11 Jul 2007

Get svn commit notification right into your inbox by using svn hook post-commit

Technology, subversion posted by Akhil Bansal

If you wish you can get notification right into your inbox when a team member commits the code. This mail will contain list of files added/deleted along with the svn diff of files that are modified. This needs some extra efforts to setup, but once it is setup it is very helpful.

This can be done by using svn hooks. Yes, svn has inbuilt hook functionality like pre-commit, post-commit, post-lock, post-unlock, pre-lock, pre-unlock, start-commit. We’ll use post-commit hook to get notifications.

First of all get a perl script from here http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commit-email.pl.in and copy it to hooks directory inside your repository directory, lets say /var/www/repos/repository_name/hooks.
Make sure to rename it as commit-email.pl, ofcourse you need perl installed on your server. Now cd to hooks directory inside you repository directory. Rename post-commit.tmpl to post-commit, and chmod 755 to post-commit and commit-email.pl . Now open post-commit in you favorite editor, and put “/usr/bin/perl /var/www/repos/commit-email.pl –from svn-notify@example.com -s ‘SVN commit notification’ ‘$REPOS’ ‘$REV’ user_whom_to_notify@example.com, another_user_to_notify@example.com” at the bottom of that file. Now open commit-email.pl and make changes in configuration section according to your requirement and server, specially svnlook path.

Congrats!, You are done ;-) .

Now your server will send email notification to user_whom_to_notify@example.com, another_user_to_notify@example.com whenever someone commits.


**For security reasons, the Subversion repository executes hook scripts with an empty environment that is, no environment variables are set at all, not even $PATH or %PATH%. Because of this, a lot of administrators are baffled when their hook script runs fine by hand,but doesn’t work when run by Subversion. Be sure to explicitly set environment variables in your hook and/or use absolute paths to programs.

It worked for me, Please let me know if it works for you too.

Did you like this? Share it:
Next Page »« Previous Page