conf/aeolus-conductor
#!/bin/bash
#
#
# aeolus-conductor startup script for aeolus-conductor
#
# chkconfig: - 99 01
# description: aeolus-conductor is the primary server process for the
# Aeolus Conductor
#
[ -r /etc/sysconfig/conductor-rails ] && . /etc/sysconfig/conductor-rails
[ -r /etc/sysconfig/aeolus-conductor ] && . /etc/sysconfig/aeolus-conductor
RAILS_ENV="${RAILS_ENV:-production}"
CONDUCTOR_DIR="${CONDUCTOR_DIR:-/usr/share/aeolus-conductor}"
CONDUCTOR_USER="${CONDUCTOR_USER:-aeolus}"
CONDUCTOR_GROUP="${CONDUCTOR_GROUP:-aeolus}"
THIN_PROG="${THIN_PROG:-thin}"
THIN_PID="${THIN_PID:-/var/run/aeolus-conductor/thin.pid}"
THIN_LOG="${THIN_LOG:-/var/log/aeolus-conductor/thin.log}"
THIN_LOCKFILE="${THIN_LOCKFILE:-/var/lock/subsys/aeolus-conductor}"
PREFIX="${PREFIX:-/conductor}"
ADDR="${ADDR:-127.0.0.1}"
export RAILS_RELATIVE_URL_ROOT=$PREFIX
RETVAL=0
STARTTIMEOUT=60
. /etc/init.d/functions
start() {
echo -n "Starting ${THIN_PROG}: "
if [ -f "$THIN_PID" ] && checkpid `cat $THIN_PID` ; then
echo_failure
echo
echo "${THIN_PROG} is already running"
exit 1
fi
$THIN_PROG start -c "$CONDUCTOR_DIR" -l "$THIN_LOG" -P "$THIN_PID" \
-a $ADDR -e $RAILS_ENV --user $CONDUCTOR_USER -g $CONDUCTOR_GROUP -d --prefix=$PREFIX \
--rackup "$CONDUCTOR_DIR/config.ru" -A rails
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
# wait until we can contact the server
# this bit is based on what the mysql init script does
TIMEOUT="$STARTTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
/usr/bin/curl --silent http://$ADDR:3000$PREFIX >& /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
touch ${THIN_LOCKFILE}
echo_success
echo
exit 0
fi
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
fi
echo_failure
echo
exit 1
}
stop() {
echo -n "Shutting down ${THIN_PROG}: "
killproc -p $THIN_PID ${THIN_PROG}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${THIN_LOCKFILE} ${THIN_PID}
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
;;
force-reload)
restart
;;
status)
status -p ${THIN_PID} ${THIN_PROG}
RETVAL=$?
;;
*)
echo "Usage: aeolus-conductor {start|stop|restart|reload|force-reload|status}"
exit 1
;;
esac
exit $RETVAL