Last updated May 21, 2010. Created by Francewhoa on July 1, 2009.
Log in to edit this page.

What about when you reboot your Apache Solr server? Are you going to type in that java -jar start.jar after each reboot? There's an easier way. We are now going to create a startup script to automatically start Apache Solr when you reboot your Ubuntu Server 8.04.x LTS.

This how-to handbook is
- For beginners.
- Using 'java -jar start.jar' method.

Type in the following command in TERMINAL to install nano text editor.

sudo apt-get install nano

Type in the following command in TERMINAL to add a new script.

sudo nano /etc/init.d/solr

TERMINAL will display a new page title “GNU nano 2.0.x”.
Paste the below script in this TERMINAL window.

#!/bin/sh -e
# Starts, stops, and restarts solr
case $1 in
        echo "Starting Solr"
        cd $SOLR_DIR
        echo "Stopping Solr"
        cd $SOLR_DIR
        $JAVA $JAVA_OPTIONS --stop
        $0 stop
        sleep 1
        $0 start
        exit 1
  • Note: In above script you might have to replace /apache-solr-1.4.0/example with appropriate directory name.

Press CTRL-X keys.
Type in Y
When ask File Name to Write press ENTER key.
You're now back to TERMINAL command line.

Type in the following command in TERMINAL to create all the links to the script.

sudo update-rc.d solr defaults

Type in the following command in TERMINAL to make the script executable.

sudo chmod a+rx /etc/init.d/solr

To test. Reboot your Ubuntu Server.
Wait until Ubuntu Server reboot is completed.
Wait 2 minutes for Apache Solr to startup.
Using your internet browser go to your website and try a Solr search.

That's it. You have successfully created a startup script to automatically start Apache Solr when you reboot your Ubuntu Server. Enjoy.




Everything works fine on Ubuntu 9.10 and apache-solr-1.5-dev

Thank you for the article.

Very useful post, thank you!

I was briefly thrown when following the instructions on using Solr with Drupal. I kept getting "Error occurred during initialization" when using the /etc/init.d/solr command to start/restart, yet starting from the command line was fine.

Google didn't initially help much, because it made it seem like there was insufficient memory, yet this was on a Debian VM with 1GB.

The problem is cut 'n' paste without looking at what I was doing. The key for anyone who doesn't use Java much seems to be in the command line, where the sample above requests 1GB of RAM ( -Xmx1024m). Not realistic when that is the entire RAM available on the machine.

This parameter specifies the maximum RAM for the Java heap (it is also possible to specify the starting, and the minimum), but it looks like Java tries to get (or at least check for) that much RAM on startup whether it needs it right away or not, and if it's not there, it fails.

So is that much RAM really necessary?

I don't yet have much experience with Solr, but some web posts seem to say for a small installation it should run on a box with 512MB *total* RAM, maybe even 384 (though not 256). Another post talks about 1.4GB of RAM being unrealistically small, though that is for a larger installation (millions of articles)

In any event, changing the JAVA_OPTIONS to be -Xmx256m eliminated the error for me, and Solr appears to run. At the least, the maximum Java heap plus the rest of Java plus the rest of RAM usage on the server (i.e. the Apache instances) should be less than the physical RAM available. For testing on a small site, RAM of 256 appeared to work just fine.

I can confirm this works for Debian 6 (on a Dreamhost VPS), Solr 3.4. I get the warning "insserv: warning: script 'solr' missing LSB tags and overrides" when i run update.rc.d, but it seems to work fine.