Tatva-Artha

meaning of "it"

Unix init script for searchd (sphinx server) and monit config

without comments

If you are using thinking_sphinx for your text search needs on a rails project, you will need to have searchd service monitored in production. Monit service allows us to monitor a unix service. However, there is no good/recommended init script that exists. Here’s one that could work for your rails3 project.

#!/bin/bash
### BEGIN INIT INFO
# File: /etc/init.d/searchd
# Provides:          searchd
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     
# Default-Stop:      
# X-Interactive:     true
# Short-Description: Start/Stop/Restart searchd
### END INIT INFO
 
EXE="/usr/bin/searchd"
CONFIG="/var/www/html/PROJECT/current/config/production.sphinx.conf"
USER='ubuntu'
 
case "$1" in
 
  'start')
    echo "Starting sphinx.."
    sudo -u $USER $EXE --pidfile --config $CONFIG
    ;;
 
  'stop')
    echo "Stopping sphinx.."
    sudo -u $USER $EXE --config $CONFIG --stopwait
    ;;
 
  'status')
    sudo -u $USER $EXE --config $CONFIG --status
    ;;
 
  'restart')
    $0 stop
    $0 start
    ;;
 
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;
 
esac

You will need to update this for the location of your sphinx CONFIG file.

If you use monit for your monitoring needs and follow the folder structure suggested in railscast, here’s your monit script for searchd monitoring may look like:

# config/deploy/templates/monit/searchd.erb
# copied to: /etc/monit/conf.d/searchd
check process searchd with pidfile <%= current_path %>/log/searchd.production.pid
  start program = "/etc/init.d/searchd start"
  stop program = "/etc/init.d/searchd stop"
  alert me@company.com

Enjoy!

http://www.tatvartha.com/wp-content/plugins/sociofluid/images/digg_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/reddit_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/stumbleupon_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/delicious_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/google_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/twitter_16.png

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Written by Sharad

September 20th, 2012 at 5:05 pm

Posted in All,Technology

Tagged with , , ,

Leave a Reply