Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Sunday, May 13, 2007

Tomcat - How to run stand alone on port 80

With Apache, all ports below 1024 are privileged ports, so normally to run Tomcat as a stand alone server, you'd have to run as root, which is a Very Bad Idea. Using the jsvc interface, it is possible to bind Tomcat to a privileged port, such as port 80.

First, change server.xml to use port 80:


$ cd $CATALINA_HOME/conf
$ sudo vi server.xml


and make this change:


<!--<Connector port="8080" protocol="HTTP/1.1" -->
<Connector port="80" protocol="HTTP/1.1"


With Tomcat 5 & 6, there will be a jsvc.tar.gz file in the bin directory of your $CATALINA_HOME directory.


$ cd $CATALINA_HOME/bin
$ sudo tar zxvf jsvc.tar.gz
$ cd jsvc-src
$ sudo autoconf
$ sudo ./configure
$ sudo make
$ sudo cp jsvc ..


I had to add a few packages on Ubuntu to compile jsvc...

$ sudo apt-get install libc6-dev g++ gcc
$ sudo apt-get install make
$ sudo apt-get install autoconf


You can start Tomcat as "tomcat" user (use which ever existing non-privileged user you want, or create a new user):


$ cd $CATALINA_HOME
$ sudo ./bin/jsvc -cp ./bin/bootstrap.jar \
-user tomcat \
-outfile ./logs/catalina.out \
-errfile ./logs/catalina.err \
org.apache.catalina.startup.Bootstrap


There is a sample starup script in the $CATALINA_HOME/bin/jsvc-src/native directory, which can be modified to work on your system:


$ cd /etc/init.d
$ sudo cp tomcat tomcat.bak (if needed, and make sure it will start on the run levels you need for startup on server boot)
$ sudo cp $CATALINA_HOME/bin/jsvc-src/native/Tomcat5.sh ./tomcat
$ sudo vi tomcat (edit for your system)


Now you can start Tomcat:


$ sudo /etc/init.d/tomcat start


More info can be found at Apache Jakarta Project - commons daemon (Java Service)

No comments:

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels