-->

Sunday, April 29, 2012

add sphinx to linux boot ( init.d )

add a init file from your app to
/etc/rc.d/init.d/searchd
with the name of the service (for sphinx it is : searchd)

file example :


#!/bin/bash
#
# Init file for searchd
#
# chkconfig: 2345 55 25
#
# description: searchd 
#
# USE "chkconfig --add searchd" to configure Sphinx searchd service
#
# by Vladimir Fedorkov Mar 1, 2006, info@astellar.com
# public domain


BASE_PATH=/usr/local/sphinx/
PID_FILE=/home/rubyapps/smifr/shared/pids/searchd.pid


# point the conf to rails smifr version
# CONFIG_FILE=$BASE_PATH/etc/sphinx.conf
CONFIG_FILE=/home/rubyapps/smifr/current/config/production.sphinx.conf
USER=haim
EXEC_PATH=$BASE_PATH/bin/
LOG_PATH=$BASE_PATH/var/log/
DATA_PATH=$BASE_PATH/var/data/
RETVAL=0
prog="searchd"


do_config() {
mkdir -p $EXEC_PATH
mkdir -p $DATA_PATH
mkdir -p $LOG_PATH


chmod 600 $CONFIG_FILE
chmod u+rwx $EXEC_PATH/*
chmod -R u+rw,go-rwx $DATA_PATH
chmod -R u+rw,go-rwx $LOG_PATH
}


do_start() {
echo "Starting $prog"
sudo -u $USER $EXEC_PATH/$prog --config $CONFIG_FILE
RETVAL=$?
echo
return $RETVAL
}


do_stop() {
echo "Stopping $prog"
if [ -e $PID_FILE ] ; then
kill -15 `cat $PID_FILE`
sleep 5
if [ -e $PID_FILE ] ; then
kill -9 `cat $PID_FILE`
fi
fi
RETVAL=$?
echo
return $RETVAL
}


case $* in


config)
do_config
;;


start)
do_start
;;


stop)
do_stop
;;


*)
echo "usage: $0 {start|stop|config}" >&2


exit 1
;;
esac


exit $RETVAL



then chkconfig --add searchd

where searchd is the service name

then you can do

service searchd start

No comments:

Post a Comment