Startup Script for Sphinx

Startup Script for Sphinx

From Debian Wiki

Jump to: navigation, search

Contents

Introduction

One of the key issues I had with Sphinx in Debian was that each time you reboot your server you need to manually startup your Sphinx server which is a pain. This quick HOWTO shows you what needs to be done to get Sphinx started at boot time.

Requirements

  • A Debian Etch base installation - Installation HOWTO here or an Ubuntu install will do.
  • Sphinx installed on the server.
  • Root access to your server.

Create a Startup Script

All that's needed here is to create a new file and add the command to startup Sphinx. This can be done as follows

cd /etc/init.d/
touch searchd
vi searchd

Then add the following to the file searchd:

#!/bin/bash
### BEGIN INIT INFO
# 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

case "${1:-}" in
  'start')
        # put the command to start sphinx
        # i.e., /usr/bin/searchd start or /usr/bin/searchd --daemon or whatever the command is
        /usr/local/bin/searchd
		;;
  'stop')
        # stop command here
		/usr/local/bin/searchd --stop
        ;;
  'restart')
        # restart command here
		/usr/local/bin/searchd --stop
		/usr/local/bin/searchd
        ;;
  *)
        echo "Usage: $SELF start|stop|restart"
        exit 1
        ;;
esac

Save your file and you're done.

Make the script executable

chmod +x searchd

Add the script to the boot sequence

update-rc.d searchd defaults

That’s it. When you’re done you should see some output similar to this on Debian Etch & Lenny:

Adding system startup for /etc/init.d/searchd ...
  /etc/rc0.d/K20searchd -> ../init.d/searchd
  /etc/rc1.d/K20searchd -> ../init.d/searchd
  /etc/rc6.d/K20searchd -> ../init.d/searchd
  /etc/rc2.d/S20searchd -> ../init.d/searchd
  /etc/rc3.d/S20searchd -> ../init.d/searchd
  /etc/rc4.d/S20searchd -> ../init.d/searchd
  /etc/rc5.d/S20searchd -> ../init.d/searchd
  /etc/rc5.d/S20searchd -> ../init.d/searchd

On Debian Squeeze you'll see the following:

update-rc.d: using dependency based boot sequencing

Remove script from boot sequence

If you ever want to remove the script from the boot sequence you'd run the following command from terminal:

update-rc.d -f searchd remove