Last updated October 5, 2010. Created by jvandyk on August 10, 2009.
Edited by rfay, phdhiren, Francewhoa. Log in to edit this page.
Attached is a startup script for RHEL / CentOS that will start your Apache Solr server at startup and cleanly shut it down at shutdown.
Download the script attached to this page, rename it to "solr", and put it at /etc/init.d/solr.
Edit the line starting with SOLR_DIR to make sure it's pointing to the location where your solr installation lives.
Make the script executable:
sudo chmod a+rx /etc/init.d/solrNow install the script using chkconfig:
sudo chkconfig --add solrThis will add the script to runlevels 3 and 5, so solr will start once the system is up. Check to make sure that things are properly set up by typing
chkconfig --listYou should see solr among the various services. You should also be able to use the service command to stop and start solr:
sudo service solr stop
Stopping Solrsudo service solr start
Starting Solrsudo service solr restart
Stopping Solr
Starting Solr| Attachment | Size |
|---|---|
| solr.txt (rename this to solr and put in /etc/init.d) | 664 bytes |
Comments
Another note: If you start
Another note: If you start getting the error below, you'll need to add a minimum memory value to the script you place in /etc/init.d/solr
Here's the error:
Error occurred during initialization of VMCould not reserve enough space for object heap
Here's the fix (in the JAVA_OPTIONS line):
JAVA_OPTIONS="-Xms128m -Xmx256m -DSTOP.PORT=8079 -DSTOP.KEY=mustard -jar start.jar"You can change the Xms (minimum) or Xmx (maximum) memory values as you see fit. These memory values work great on my server running two drupal sites that get moderate traffic and only a few searches /new nodes per hour.
__________________
Me, to webchick, in IRC: "ice cream kittens!"
Work: Midwestern Mac, LLC | Personal: Life is a Prayer.com
Thanks. I had this problem
Thanks. I had this problem and your suggestions works
GoDaddy Coupons - Save money on domains and web hosting
Glumbo Shopping - Compare prices for millions of products to get the lowest price
Thanks!
Great tutorial
Unable to get the script to create an instance of apache-solr
I have followed the instructions above exactly and I get a screen that says Starting and/or Stopping solr service. But it never goes through all the printout like it does when the commands are typed manuallyjava -jar start.jarat the apache-solr/example prompt. Permissions of the folder are 755 and I tried changing ownership and moving the example directory around, but no luck. I'm using apache 2.2.14 on centos. Any ideas would be greatly appreciated.I can manually get this to work without the script--just can't get it to work automatically or manually via
sudo service solr start.Thanks--
Ok, I finally got this script to work. The problem was the path to java. Using whereis--I was trying usr/share/java since usr/bin/java didn't exist. oops.
The location of my java was
/usr/local/jdk1.6.0_17/jre/bin/java.protoplasm
Automatic apache solr start on boot
This works manually to start and stop, but I can't get it to work automatically to start apache solr on an apache automagic restart on a Centos apache 2.2 server. Any suggestions appreciated.
UPDATE: Finally got this to work automatically on an apache reboot. I believe the problem was related to the file owner of where I placed the solr distribution with the example file. When I placed it in a location (opt) that had root ownership, then it worked automatically with apache reboot.
protoplasm
The example starts the solr
The example starts the solr service under the root user. How to get it running by another user? If I use sudo it works when starting it manually but it fails on reboot since there is no terminal available.
You use edit your sudoers
You can edit your sudoers file to allow your solr (or other) user to not require a tty: http://serverfault.com/questions/111064/sudoers-how-to-disable-requirett...
Full path to chkconfig and service
On my CentOS box the chkconfig and service commands are not in path, so I had to supply the full path. If you run into trouble having messages like
sudo: chkconfig: command not found, simply use the full path:sudo /sbin/chkconfig --add solr/sbin/chkconfig --list
sudo /sbin/service solr stop
Other than that this works like a charm :)
Great help
This is a great resource. I had to create the /var/solr directory and the /var/log/solr file.
After that, everything went fine. Now I can issue the service commands [start|stop|restart]. A fourth option, available with the httpd daemon, is status. It'd be nice to have it with the Solr server.
Thanks
On my little knowledge I sit
To gauge the depth of my ignorance. (T.S. Mombeya)
service solr does not support chkconfig
if the above message appears on your CentOs box
add the following lines after bin/bash
# chkconfig: 2345 95 20# description: Some description
# What your script does (not sure if this is necessary though)
# processname: myscript
for more see http://stackoverflow.com/questions/2150767/how-to-start-solr-automatically
thx
thanks, you saved my day
solr.txt file format
If the message "bad interpreter: No such file or directory" appears when attempting to execute the attached script, you need to change the file format by following the instructions found here:
http://www.gizmola.com/blog/archives/87-Linux-shell-scripting-bad-interp...