sunspot_solrの起動スクリプト

amazon linuxでのsunspot_solrの起動スクリプトです。

#!/bin/sh -e
# chkconfig: 2345 85 15

set -e
APP_PATH=/path/to/app
RAILS_ENV=prodcution

start_sunspot(){
        echo "Starting Sunspot"
        cd $APP_PATH && /usr/local/bin/bundle exec rake sunspot:solr:start $RAILS_ENV
}

stop_sunspot(){
        echo "Stopping Sunspot"
        cd $APP_PATH && /usr/local/bin/bundle exec rake sunspot:solr:stop $RAILS_ENV
}

COMMAND="$1"
shift

case $COMMAND in
status)
    ;;
start|stop|restart)
    $ECHO
    if [ "$COMMAND" = "stop" ]; then
        stop_sunspot
    elif [ "$COMMAND" = "start" ]; then
        start_sunspot
    elif  [ "$COMMAND" = "restart" ]; then
        stop_sunspot
        sleep 1s
        start_sunspot
        exit 0
    fi
    ;;
esac