« Setting up a Ruby on Rails server - Part 4 - Litespeed a web server | Home | Setting up a Ruby on Rails server - Part 6 - Axigen easy mail server »

Setting up a Ruby on Rails server - Part 5 - Java - Tomcat - Ant

By Nick | April 4, 2007

Some of you may think, why on earth or you using Java? Well, I use every language program that looks good to me. PHP to run this blog, Rails to develop my own sites and Java because it has an awesome search engine Lucene and on top some nice icing in the form of Solr.

In order to get Solr running you need to have Java, Tomcat and Ant installed first.

Java installation:

Download the latest Java jdk_xx.bin file
chmod +x jdk_xx.bin #to make it executable
./jdk_xx.bin

Now you make sure that all the paths are correct. I added the following lines to /etc/profile to do it (also added path for Tomcat and Ant), maybe there is a cleaner method for it.

export PATH=/usr/java/jdk_xx/bin:/usr/local/ant/bin:$PATH
export JAVA_HOME=/usr/java/jdk.xx/
export CATALINA_HOME=/usr/local/tomcat
export ANT_HOME=/usr/local/ant

Now you should restart your server to see if JAVA_HOME is still set. Run java -v to see if you get your Java version back. If you do, it means Java is installed correctly. Now on to Tomcat.

Tomcat installation:

- /usr/sbin/adduser tomcat #add a tomcat user
chown -R tomcat /usr/local/tomcat
- wget http://apache.scarlet.be/tomcat/tomcat-5/v5.5.17/bin/apache-tomcat-5.x.x.tar.gz #download latest Tomcat version
tar -zxvf apache-tomcat-5.x.x.tar.gz
- mv apache-tomcat-5.x.x /usr/local/tomcat

Now we have to make sure Tomcat starts up when the server goes down unexpectedly, so lets make a Tomcat startup script.

Create the file /etc/rc.d/init.d/tomcat and place the following in it:

#!/bin/bash
#
# Startup script for Tomcat

start_tomcat=/usr/local/tomcat/bin/startup.sh
stop_tomcat=/usr/local/tomcat/bin/shutdown.sh

start() {
echo -n "Starting tomcat: "
su -l tomcat -c ${start_tomcat}
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
su -l tomcat -c ${stop_tomcat}
echo "done."
}

# See how we were called
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac

exit 0

Now make the file executable and place it in the right directories:


chmod +x tomcat
cd /etc/rc3.d
ln -s /etc/init.d/tomcat S71tomcat
ln -s /etc/init.d/tomcat K01tomcat

BTW K stands for stopping and S stands for starting and the number is the order in which all the files are executed. So if Tomcat needs to be started before another service at startup make sure it gets a lower S number than the other service.

That’s it for Tomcat. Restart your server and see if Tomcat starts up.

Now the last part is installing Ant, which is also the easiest.

Ant installation:

wget http://apache.scarlet.be/ant/binaries/apache-ant-1.6.x-bin.tar.gz
tar -zxvf apache-ant-1.6.x-bin.tar.gz
mv apache-ant-1.6.x-bin /usr/local/ant

And now you are ready to install Solr or any other Java utility. Next time I’ll give some explanation about my mailserver.

Topics: Uncategorized |

One Response to “Setting up a Ruby on Rails server - Part 5 - Java - Tomcat - Ant”

  1. Brian Says:
    July 12th, 2007 at 8:05 pm

    Nick, thanks for the posts. I’ve just started working with acts_as_solr, could you explain how you get the faceted search results? I’ve been trying to learn from the documentation, but I’m kinda stumped.

    Brian

Comments