Barefoot Development

Ruby, mongrel_cluster, ferret and Linux PATHs

I have less hair. There's no two ways about it. In a fit of self-pity this weekend, I considered getting some of that great spray paint to solve the issue, but instead, I've decided to swear off various un*x distributions. Can't we all just get along? I digress.

While preparing a recent Rails application for production, I came across some odd issues with various ruby-powered applications and gems. I struggled to understand why these apps failed to launch on startup, but would work without a hitch when run "by hand" at the command prompt. After tearing through boot logs, application logs and a good portion of my hair, I finally figured it out: it's a PATH issue. On each of the boxes in question (a few Fedora Core and two RHE4 machines), ruby was installed in /usr/local/bin, and that, my friends, is not in the default PATH for root. So, I thought, "Easy fix. Simply add /usr/local/bin to the PATH in a system wide script like /etc/profile." Alas, t'was not to be. These newer incarnations of RedHat linux have the added security of SELinux, which, among many positive things, sets and unsets root's PATH multiple times during the boot sequence. In the end, we had to add /usr/local/bin directly within each component's startup script. The Rails (and gems) components we are using are mongrel, mongrel_cluster, and ferret (using the DRb server). For those keeping score at home, that's a 9.7 on the new technology in production (NTIP) scale. So you can keep your hair in tact, here are the startup scripts we're using.

Mongrel cluster:

#!/bin/bash
#
# Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com
#
# mongrel_cluster Startup script for Mongrel clusters.
#
# chkconfig: - 85 15
# description: mongrel_cluster manages multiple Mongrel processes for use \
# behind a load balancer.
#

CONF_DIR=/etc/mongrel_cluster
RETVAL=0
PATH=/usr/local/bin:$PATH

# Gracefully exit if the controller is missing.
which mongrel_cluster_ctl >/dev/null || exit 0

# Go no further if config directory is missing.
[ -d "$CONF_DIR" ] || exit 0

case "$1" in
start)
mongrel_cluster_ctl start -c $CONF_DIR
RETVAL=$?
;;
stop)
mongrel_cluster_ctl stop -c $CONF_DIR
RETVAL=$?
;;
restart)
mongrel_cluster_ctl restart -c $CONF_DIR
RETVAL=$?
;;
*)
echo "Usage: mongrel_cluster {start|stop|restart}"
exit 1
;;
esac


Ferret DRb server:
#!/bin/bash
#
# This script starts and stops the ferret DRb server
# chkconfig: 2345 89 36
# description: Ferret search engine for ruby apps.
#
# Sean Brown, Partner at Barefoot, Inc.
#
# save the current directory
CURDIR=`pwd`
PATH=/usr/local/bin:$PATH

RORPATH="/path/to/ror_root"

case "$1" in
start)
cd $RORPATH
echo "Starting ferret DRb server."
FERRET_USE_LOCAL_INDEX=1 \
script/runner -e production \
vendor/plugins/acts_as_ferret/script/ferret_start
;;
stop)
cd $RORPATH
echo "Stopping ferret DRb server."
FERRET_USE_LOCAL_INDEX=1 \
script/runner -e production \
vendor/plugins/acts_as_ferret/script/ferret_stop
;;
*)
echo $"Usage: $0 {start, stop}"
exit 1
;;
esac

Labels: , , , ,

1 comments

  1. Blogger doktahahpah said:  

    LOL I just arrived at EXACTLY the same conclusion AND solution.

    And I don't have a lot of hair left either. ;-)

Post a Comment

« Home