Ruby-on-Rails: Mongrel Configuration

I actually forgot I had this site, until Alec Jacobson made a comment and reminded me of it’s existence  (oops).   Will attempt to remember to post more, but I’m just not the blogging sort of person.

So this post pertains to some work I actually did about a month ago, which would have made excellent material here, but (see paragraph above)….  At work we needed a way to keep track of production issues requiring engineering support.  I had already come across the most excellent Retrospectiva and had actually tried to set it up before but failed at the Apache/fastCGI integration step.  And so it was, a little over 1 year later, I tried again.  The initial setup went smoothly, but once again I found myself having difficulty integrating with Apache.

Retrospectiva up and running

This time I opted for Mongrel.  Unfortunately I couldn’t find a lot of information on configuring Mongrel, so it took a lot of trial and error.  Below, reconstructed from my notes, are the steps that I had to take to configure it and get it working.  Note that this transpired on Fedora Core 11.

  1. Follow the Retrospectiva installation instructions for setting up and installing gems.
    Note that the command for installing the mysql gem on Fedora is:

       gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
  2. Install Mongrel per the Retrospectiva install guide
  3. Configure Mongrel to run as a cluster:
       mongrel_rails cluster::configure -e production -p 8000 -a -N 3 -c /var/www/retrospectiva
  4. Check that the cluster works (you should be able to browse to and see the website):
    mongrel_rails cluster::start
  5. This step is partially referenced from another blog.  Set up mongrel to start on boot:
       mkdir /etc/init.d/mongrel_cluster
       ln -s /usr/lib64/ruby/gems/1.8/gems/mongrel_cluster-X.Y.Z/resources/mongrel_cluster /etc/init.d/mongrel_cluster
       chmod +x /etc/init.d/mongrel_cluster

    Note that depending on your setup, you might need to use /usr/lib rather than /usr/lib64.

  6. Edit /etc/init.d/mongrel_cluster, set user=root (yes, I was bad.  You should use limited account here, but I didn’t feel like troubleshooting permission errors)
  7. Add the mongrel_cluster as a service:
       /sbin/chkconfig --level 345 mongrel_cluster on
  8. Finally, link your mongrel_cluster.yml from your app’s config directory to /etc/mongrel_cluster:
       mkdir -p /etc/mongrel_cluster
       ln -s /var/www/retrospectiva/config/mongrel_cluster.yml /etc/mongrel_cluster/retrospectiva.yml
  9. Mongrel should be starting on boot now. You can test by rebooting and issuing:
       /etc/init.d/mongrel_cluster start (or stop)
  10. Configure Apache, following these directions.  Note that Apache might not be able to pass off to Mongrel (check the error log).  It may be necessary to edit SELinux to allow Apache scripts to access the network (in my case I enabled all ports for tcp, using the seedit-gui program).
  11. Make sure Apache is starting on boot:
        chkconfig --list|grep http

    You get something like this:  httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

    Now run:

        chkconfig httpd on

    This will set it up to start each time you boot.  Verify that it set correctly:

        chkconfig --list|grep http

    You should get:  httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

That’s all I have.  Note that this sets up your rails application as the sole Apache output.  Hosting other static content or web applications requires more configuration than I could figure out at this time.