#!/bin/sh # $Id: sphinx,v 1.1 2008-08-18 17:59:29 markuspetrux Exp $ # # sphinx - This shell script takes care of starting and # stopping Sphinx search daemon. # It also has options to build main and delta indexes. # # ********** WARNING ********** # This script may not work as-is on your environment. # Please, use it only if you know what you are doing. # ********** WARNING ********** ############################### ### WARNING WARNING WARNING ### ############################### echo "Edit, review and adjust script to suit your needs." exit 1 ############################### ### WARNING WARNING WARNING ### ############################### # Source function library. . /etc/rc.d/init.d/functions ##################### ### Program paths ### ##################### BASE_PATH=/usr/local/sphinx SEARCHD=${BASE_PATH}/bin/searchd INDEXER=${BASE_PATH}/bin/indexer CONFIG_FILE=/data/sphinx/sphinx.drupal_example.conf PID_FILE=${BASE_PATH}/var/log/drupal_example.searchd.pid LOCK_FILE=/var/lock/subsys/searchd.drupal_example PS=/bin/ps HEAD=/usr/bin/head GREP=/bin/grep WGET=/usr/bin/wget STAT=/usr/bin/stat KILL=/bin/kill USLEEP=/bin/usleep ################################# ### Drupal site/index options ### ################################# # Name of main and delta indexes. # Note main index name should not contain numeric suffix. MAIN_INDEX=index_drupal_example_main DELTA_INDEX=index_drupal_example_delta ############################# ### Script starts here... ### ############################# RETVAL=0 # # Start searchd daemon. # start() { echo -n $"Starting searchd: " daemon $SEARCHD --config $CONFIG_FILE RETVAL=$? echo [ $RETVAL = 0 ] && touch $LOCK_FILE return $RETVAL } # # Stop searchd daemon. # stop() { echo -n $"Stopping searchd: " for killlevel in 15 9; do if [ -e $PID_FILE ]; then $KILL -$killlevel `cat $PID_FILE` for i in `seq 1 10`; do if [ -e $PID_FILE ]; then echo -n "." $USLEEP 500000 else break fi done fi done if [ -e $PID_FILE ]; then echo_failure RETVAL=1 else echo_success RETVAL=0 fi echo [ $RETVAL = 0 ] && rm -f $LOCK_FILE $PID_FILE return $RETVAL } # # Display ps auxw for searchd daemon. # status() { if [ -f $LOCK_FILE ]; then $PS auxw | $HEAD -n 1 $PS auxw | $GREP $SEARCHD | $GREP -v grep RETVAL=0 else echo "Sphinx searchd is stopped." RETVAL=1 fi return $RETVAL } # # Build specified main index. # build_main_index() { if [ -f $LOCK_FILE ]; then echo $INDEXER --config $CONFIG_FILE --rotate ${MAIN_INDEX}${1} $INDEXER --config $CONFIG_FILE --rotate ${MAIN_INDEX}${1} RETVAL=$? else echo $INDEXER --config $CONFIG_FILE ${MAIN_INDEX}${1} $INDEXER --config $CONFIG_FILE ${MAIN_INDEX}${1} RETVAL=$? fi return $RETVAL } # # Build delta index. # build_delta_index() { if [ -f $LOCK_FILE ]; then echo $INDEXER --config $CONFIG_FILE --rotate $DELTA_INDEX $INDEXER --config $CONFIG_FILE --rotate $DELTA_INDEX RETVAL=$? else echo $INDEXER --config $CONFIG_FILE $DELTA_INDEX $INDEXER --config $CONFIG_FILE $DELTA_INDEX RETVAL=$? fi return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; main) build_main_index $"$2" ;; delta) build_delta_index ;; *) echo $"Usage: sphinx {start|stop|restart|status|main|delta}" echo " start - Start searchd daemon." echo " stop - Stop searchd daemon." echo " restart - Stop and then start searchd daemon." echo " status - Display ps auxw for searchd daemon." echo " main [X] - Build specified main index (X is opcional)." echo " delta - Build delta index." exit 1 esac exit $RETVAL