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/solr
Now install the script using chkconfig
:
sudo chkconfig --add solr
This 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 --list
You 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 Solr
sudo service solr start
Starting Solr
sudo 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:
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.
__________________
Personal site: www.jeffgeerling.com
Thanks. I had this problem
Thanks. I had this problem and your suggestions works
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.jar
at 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: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
service solr does not support chkconfig
if the above message appears on your CentOs box
add the following lines after bin/bash
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...
Thanks. That did help :)
Thanks. That did help :)
iptables and script
When you are using the above attached script with this options
JAVA_OPTIONS="-Xmx1024m -DSTOP.PORT=8079 -DSTOP.KEY=mustard -jar start.jar"
and you have iptables configured on your system you will not be able to stop it with
/etc/init.d/solr stop
because iptables will block port 8079 on the localhost.
You have to extend your iptables-configuration with
iptables -A TCP -p tcp -m tcp -s localhost -d localhost --dport 8079 -j ACCEPT
or similar to that regarding the iptables-config you are using.
File Naming
Should the script be named solr or solr.sh? No file extension?
//G
Start.jar -- Stop Solr -- Connection Refused?
Hi,
I have followed the instructions exactly on how to get Solr to start automatically on CentOS and am still stuck. I am on Drupal 6 with Solr 1.4.1. Solr works fine. But when the machine is rebooted or Apache is bounced, it does not start uop automatically -- I must do start -java start.jar every single time. But I can't stop it to test the script.
My java path is correct and I have not changed the script at all, aside from adding /drupal to the path for the start.jar file. Here it is:
I have registered the service using chkconfig and it appears in the chkconfig --list. It also has the correct permissions. However, I cannot STOP Solr! When I issue either:
service solr stop
/etc/init.d/solr stop
I get this error:
I also have nothing configured in iptables, FYI. Traffic through 8079 should be fine. Anyone have any idea what is happening here?
If I remove "/drupal" from SOLR_DIR then I was getting "Unable to access start.jar." That's why I added it.
Thanks,
Garrett
Same problem here.
Same problem here. "Connection refused."