Friday, August 27, 2010

monitor mongrel for rails application

#! /bin/bash
# ChetanM chetan.muneshwar@gmail.com

# Add to this script to /usr/bin/path
# Add */1 * * * * /usr/bin/monome in crontab

# please specify path of rails ROOT eg /home/myapp/ [not /home/myapp/public]
RAILS_ROOT=
cd $RAILS_ROOT/
pii()
{
PROCNAME=$1
PIDS=`ps -efa | grep $PROCNAME | grep -v grep | awk '{ print $2 }'`
for ff in $PIDS
do
echo "$ff"
done
}
mongrel_array=(3078 3079 3080 )
for (( i = 0 ; i < ${#mongrel_array[*]}; i++ ))
do
pii tmp/pids/mongrel.${mongrel_array[i]}.pid >/tmp/dat$$$

if [ "`cat /tmp/dat$$$`" == "" ] ;then
rm -rf tmp/pids/mongrel.${mongrel_array[i]}.pid
mongrel_rails cluster::restart --only ${mongrel_array[i]}
else
echo "accha hai "
fi
done

No comments: