-
-
Recent Posts
- It has arrived!
- A letter I wrote to my Senator today about PIPA/SOPA
- Building a new computer is fun!
- Don’t use the default Solr configuration files, ever!
- Authentication with Node.js and Zend Framework.
Recent Comments
- Anthony Wlodarskis Blog: Authentication with Node.js and Zend Framework | Scripting4You Blog on Authentication with Node.js and Zend Framework.
- Anthony Wlodarskis Blog: Authentication with Node.js and Zend Framework on Authentication with Node.js and Zend Framework.
- PHPDeveloper.org: Anthony Wlodarskis Blog: Authentication with Node.js and Zend Framework on Authentication with Node.js and Zend Framework.
- Anthony Wlodarskis Blog: Authentifizierung mit Node.js und Zend Framework | PHP Boutique on Authentication with Node.js and Zend Framework.
- Using Phergie with Upstart — Phergie on Using Phergie with Upstart (a.k.a. Phergie #winning)
Archives
- January 2012
- November 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
Categories
- C
- computer hardware
- database
- fun
- html5
- Java
- JavaScript
- Jetty
- Linux
- node
- PHP
- Security
- Solr
- Uncategorized
- Upstart
- zend framework
Meta
- Log in
- Entries RSS
- Comments RSS
- WordPress.org
Using Solr with Upstart instead of init.d
You can use the default Solr (lucene.apache.org/solr/) examples right out of the box with Upstart to emulate a working daemon on your servers. Unpack the Solr download anywhere on your server and clone the “example” directory to a unique folder else where in your file system. I choose “/opt/solr/solr-anthony” for example (now known as SOLR_HOME). Inside of SOLR_HOME you will see a start.jar file, this is Jetty (jetty.codehaus.org/jetty/). Jetty is a Java servlet container and is a good alternative to using Tomcat or other heavy containers. So how do you get this to work with Upstart? Very easily I say!
If you are on Debian/Ubuntu/Fedora this will work for you no problem. Inside of ‘/etc/init’ you can create init scripts that Upstart reacts upon. Things like ‘service apache2 restart’ do a look up in this directory find the right script and apply the logic necessary to the daemon. In ‘/etc/init’ I placed a file called ‘solr-anthony.conf’. The trick to the naming convention is that whatever you name your configuration file that will be the name of the service sans the ‘.conf’ extension. For example if you create ‘foobar.conf’ in ‘/etc/init’ then ‘service foobar stop’ would be a valid command. So now that you have created the file, what are its contents? As follows:
description "Solr Search Server" # Make sure the file system and network devices have started before # we begin the daemon start on (filesystem and net-device-up IFACE!=lo) # Stop the event daemon on system shutdown stop on shutdown # Respawn the process on unexpected termination respawn # The meat and potatoes exec /usr/bin/java -Xms128m -Xmx256m -Dsolr.solr.home=/opt/solr/solr-anthony/solr -Djetty.home=/opt/solr/solr-anthony -jar /opt/solr/solr-anthony/start.jar >> /var/log/solr-anthony.log 2>&1
With Solr there is an important configuration that you must pass in and that is Solr’s home directory, if you look inside of the default ‘example’ folder from Apache you will find the ‘solr’ directory, this is it. Additionally through trial and error (I am not a Java developer…) I found that you have to set the Jetty home directory as well or else there are certain files that the JVM will not know exist. The Jetty home directory is where the ‘start.jar’ file lives.
Optionally I hard coded my path to the Java executable, it is not a bad idea, of course you can parse that out in bash if necessary using the ‘which’ command. Also I set the amount of memory the JVM can start with and the amount of memory that the JVM can consume at a maximum for this application. If you want to log Jetty or the Solr application I send all output via redirection to /var/log/solr-anthony.log. ’2>&1′ in Linux means route stderr to where stdout is going.
Comments are closed.