I am manually installing the latest version of Tomcat on my Debian Linux server without using its package management system (dpkg). I downloaded Tomcat 7.0.41 from the Tomcat 7.0 download page. Then I unpacked the Tomcat tarball (apache-tomcat-7.0.41.tar.gz) into the /usr/local directory because it seems like a proper place for manually installed software.
/usr/local tar xzf ~/apache-tomcat-7.0.41.tar.gz
Tomcat requires JDK or JRE to run, so make sure it is installed already. Since we need JDK to compile Apache Commons Daemon, we should install JDK. Later, we can remove JDK and install JRE. Tomcat will work fine with JRE, but some sophisticated Web applications, such as OpenCMS, requires JDK instead of JRE. On Debian, we can use apt-get to install JDK.
apt-get install openjdk-7-jdk
On OpenBSD, we can use pkg_add to install JDK.
pkg_add -i -v jdk
Once we have both Java and Tomcat installed on the system, we need to find a way to start Tomcat automatically on every boot. It is recommended to use Apache Commons Deamon for this purpose. Tomcat is distributed with the source code for the Daemon. In the bin directory of Tomcat, we find a tarball called commons-daemon-native.tar.gz. Let's compile Apache Commons Daemon. This will produce an executable file jsvc for Linux and *BSD which can be used to start any program or Java application in daemon mode. First, unpack the Commons Daemon tarball into your HOME or a temporary location.
tar xzf commons-daemon-native.tar.gz
Then, define an environment variable JAVA_HOME to point to the JDK directory. The configure script in the source uses this variable to find JDK.
export JAVA_HOME=/usr/local/jdk-1.6.0
I think libcap-dev should be installed along with gcc and make.
apt-get install gcc make libcap-dev
Go to the unix subfolder and run the configure script. This assumes that gcc and GNU make are already on your system.
cd commons-daemon-1.0.15-native-src/unix ./configure
Then, run make.
make
This will produce jsvc. Copy it to the bin directory of Tomcat.
cp jsvc /usr/local/apache-tomcat-7.0.41/bin
Starting Tomcat with jsvc needs a bit of tweaking. First, learn about its command parameters.
jsvc --help
Run jsvc to start Tomcat as daemon as shown below. Then, use lynx or Firefox to check Tomcat at http://127.0.0.1:8080/. If that works, we can turn it into a script. On Debian Linux and OpenBSD, I would put into /etc/rc.local something like this:
export JAVA_HOME=/usr/local/jdk-1.6.0
/usr/local/tomcat-7.0.41/bin/jsvc -classpath /usr/local/tomcat-7.0.41/bin/bootstrap.jar:/usr/local/tomcat-7.0.41/bin/tomcat-juli.jar -outfile /tmp/catalina.out -errfile /tmp/catalina.err -Dcatalina.home=/usr/local/tomcat-7.0.41 -Dcatalina.base=/home/tomcat7 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/home/tomcat7/conf/logging.properties -pidfile /tmp/tomcat7.pid -user tomcat7 org.apache.catalina.startup.Bootstrap
You may notice that my settings are peculiar in a way. Basically, I create a user "tomcat7" and use its HOME directory as CATALINA_BASE. The jsvc command is run with -user parameter so it will start Tomcat as the specified user (tomcat7). To stop Tomcat, run jsvc like this:
JAVA_HOME=/usr/local/jdk-1.6.0 /usr/local/tomcat-7.0.41/bin/jsvc -classpath /usr/local/tomcat-7.0.41/bin/bootstrap.jar:/usr/local/tomcat-7.0.41/bin/tomcat-juli.jar -stop -pidfile /tmp/tomcat7.pid org.apache.catalina.shutdown

