Skip to content

Instantly share code, notes, and snippets.

@ancorcruz
Created July 31, 2009 10:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ancorcruz/159164 to your computer and use it in GitHub Desktop.
Save ancorcruz/159164 to your computer and use it in GitHub Desktop.
Thinking Sphinx init.d script
#!/bin/bash -e
### BEGIN INIT INFO
# Provides: thinking_sphinx
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop Sphinx daemon for Thinking Sphinx
### END INIT INFO
CONFIG_FILE=/etc/default/thinking_sphinx.conf
. $CONFIG_FILE || exit
if [[ `whoami` != 'root' ]]
then echo "Only root can use $PROGRAM_NAME tasks"; exit 1
fi
case "$1" in
start)
echo "Starting $PROGRAM_NAME"
cd $APP_PATH
sudo -u $USER RAILS_ENV=$RAILS_ENV rake thinking_sphinx:start
echo
;;
stop)
echo "Stopping $PROGRAM_NAME"
cd $APP_PATH
sudo -u $USER RAILS_ENV=$RAILS_ENV rake thinking_sphinx:stop
echo
;;
rebuild)
echo "re-Building (Stop/Index/Start) $PROGRAM_NAME"
cd $APP_PATH
sudo -u $USER RAILS_ENV=$RAILS_ENV rake thinking_sphinx:rebuild
echo
;;
restart)
echo "re-Starting $PROGRAM_NAME"
cd $APP_PATH
sudo -u $USER RAILS_ENV=$RAILS_ENV rake thinking_sphinx:restart
echo
;;
delayed_delta)
echo "Process stored delta index requests"
cd $APP_PATH
sudo -u $USER RAILS_ENV=$RAILS_ENV rake thinking_sphinx:delayed_delta
echo
;;
*)
echo "Usage: $0 {start|stop|restart|rebuild|delayed_delta}"
exit 1
esac
USER='user'
APP_PATH='/path/to/your/rails/app/current'
RAILS_ENV='production'
PROGRAM_NAME='Thinking Sphinx'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment