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 mongrel_cluster.sh 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 mongrel_cluster.sh 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.