Autostarting Mongrel clusters in FreeBSD 6.x on bootup

Update April 2, 2009: This post is REALLY old. Do yourself a favor and install Passenger. I have and it’s a life saver for my Rails sites. No more crashing mongrels, or mongrels that don’t want to restart. Just sites that know they need to spin up if they’re down.

Jeez this has been a confusing day. I’ve been trying to figure out why the mongrel clusters powering my websites weren’t starting after a reboot of my servers. I’m initializing the reboots so don’t worry that my servers are unstable. 🙂 they’re not. They’re well-behaved children.

FreeBSD has the /usr/local/etc/rc.d directory for shell scripts that will autostart services for you. Kinda like the “Startup” directory in windows. Great. So I found a shell script someone had written and sent in this email on the Mongrel-users mailing list. I copied that to the rc.d directory and placed the require mongrel_cluster_enable=”YES” line into /etc/rc.conf.


Nothing. Apache was starting. Mysql was starting. WTF.

I spent a while trying to figure out where I might be able to find a log of what was going on… Ah. /var/log/console.log. Great. I could see it talking about “local package intialization”. Starting Apache… Starting mysql… but what’s this…

env: ruby: No such file or directory

That’s suspicious. I figured that had to do with my mongrel servers since they were the only ruby items I’m autostarting. Okay. What does that mean though?

It was related to the shebang line of the mongrel_cluster_ctl command that’s run from the shell script. I ran “/usr/bin/env ruby” from the cmd line and it just didn’t do anything. Stopping it, I tried running “/usr/bin/env ruby -v”. Ah ha. That works. Telling me the version of ruby. So I knew the shebang line wasn’t WRONG. Turns out it was just being misinterpreted by the shell script. It didn’t have any idea where to find the “ruby” program.

Well, I tried modifying the shebang line to point directly at the ruby interpreter located at /usr/local/bin/ruby. That sorta worked but now I got some fatal ruby errors. Huh? I know people have gotten it to work just using the supplied shell script so I figured it has to be something simple so I go back to using the env ruby shebang line.

Turns out someone had run across this already. I did a little searching on “/usr/bin/env freebsd rc.d”. Ultimately I came across a post talking about the very problem I was having. Almost. He wasn’t talking about mongrel clusters, just a single ruby server. But the concept was the same. FINALLY. A solution.

The author of that post talks about a solution at the bottom of his post. His “simplest solution”. Appending the path to “ruby” to the PATH environment variable. The simple solution was to put the following line in the line after the call to rc.subr.


That worked. One line and I coulda had this solved hours ago. <sigh> ah well. hope this helps someone else.


  1. whenever your father starts to talk like this, all i hear is blah, blah, blah. you are speaking in a foreign language i have no hope of ever understanding. and i am good with languages
    oh darn, ohio state just beat michigan.

  2. UNIX floors you like Windows floors me. The problem here is that I understood everything you were saying and figured you probably needed an environment variable RUBY_HOME=/usr/local/ruby and then needed to add it to the PATH variable. In Windows this is down in the bowels of the dreaded “Control Panel” and it too is called PATH in the environment variable window.

    The bigger problem is people that only hear blah blah when one is speaking very clear and understandable GEEK SPEAK. Really proud that you have mastered a new skill on your way out of the scourge of GATES SPEAK on the way to UNIX nervana. {:-)

Comments are closed.