#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          sphinx
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Sphinx search daemon init script
# Description:       Init script for sphinx indexer
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/var/lib/gems/1.8/bin
DAEMON="/usr/bin/rake"
CONF_DIR=/var/zena/current

RETVAL=0

# Gracefully exit if the controller is missing.
test -x $DAEMON || exit 0

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

case "$1" in
    start)
      cd $CONF_DIR && $DAEMON RAILS_ENV=production sphinx:start
      RETVAL=$?
  ;;
    stop)
      cd $CONF_DIR && $DAEMON RAILS_ENV=production sphinx:stop
      RETVAL=$?
  ;;
    restart)
      cd $CONF_DIR && $DAEMON RAILS_ENV=production sphinx:restart
      RETVAL=$?
  ;;
    *)
      echo "Usage: sphinx {start|stop|restart}"
      exit 1
  ;;
esac      

exit $RETVAL


