Drupal 6: Setting up a script to ensure the Apache Solr java process is running
I recently found some time to switch my site’s search framework from Lucene to Apache Solr. The module’s README.txt makes installation for small production sites easy and straight forward.
Following the installation guide, I started the java Solr process by entering the right directory and executing the java jar..
Everything was up and running in minutes.. until I closed my terminal and the java service ended with my shell process. Short term, I decided to writing a bash shell script to ensure Solr is running, and cron it to run every five minutes.
Here are the contents of my bash shell script:
I added the following cronjob:
A better option would be to setup initialization scripts for the process (/etc/init.d/), or install Solr as a more permanent solution, but I guess this will do for the time being :) …
Part 2, Using Supervisor (updated: 2011/04/12)
As mentioned above using a cronjob is probably not the best solution. I decided to install and configure supervisord to monitor the process.
Unfortunately supervisor was not available for for Centos 5.5 (RHEL):
Luckily I found some RPMs via http://rpmfind.net. I installed supervisor and its one dependency:
Next I create a simple shell script to start the Solr process and made the script executable. NOTE: file contents have been simplified:
Last I added a few line to my supervisor conf file (/etc/supervisord.conf):
Upon restarting supervisor, solr started automatically
I killed the script and it immediately came back (with a different process ID):