File gitorious-ultrasphinx.init of Package gitorious

### BEGIN INIT INFO
# Provides: gitorious-ultrasphinx
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Description: Gitorious search
# Short-Description: Gitorious search
### END INIT INFO

# Check for existence of needed config file and read it
GITORIOUS_SYSCONFIG=/etc/sysconfig/gitorious
test -r $GITORIOUS_SYSCONFIG || { echo "$GITORIOUS_SYSCONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

# Read config
. $GITORIOUS_SYSCONFIG

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
SPHINX_BIN=/usr/bin/searchd
test -x $SPHINX_BIN || { echo "$SPHINX_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

RETVAL=0
START_CMD="cd ${GITORIOUS_DIR}/ && rake ultrasphinx:daemon:start RAILS_ENV=production"
STOP_CMD="cd ${GITORIOUS_DIR}/ && rake ultrasphinx:daemon:stop RAILS_ENV=production"
RESTART_CMD="cd ${GITORIOUS_DIR}/ && rake ultrasphinx:daemon:restart RAILS_ENV=production"
STATUS_CMD="cd ${GITORIOUS_DIR}/ && rake ultrasphinx:daemon:status RAILS_ENV=production"
LOCK_FILE=/var/lock/git-ultrasphinx
PID_FILE=${GITORIOUS_DIR}/db/sphinx/log/searchd.pid
 
case "$1" in
  start)
    /bin/su - ${GITORIOUS_USER} -c "$START_CMD"
    ;;
  stop)
    /bin/su - ${GITORIOUS_USER} -c "$STOP_CMD"
    ;;
  status)
    /bin/su - ${GITORIOUS_USER} -c "$STATUS_CMD"
    ;;
        restart)
    /bin/su - ${GITORIOUS_USER} -c "$RESTART_CMD"
                ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    RETVAL=1
esac
exit $RETVAL