LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Blogs > Ibacsoft`s Slackware Blog
User Name
Password

Notices

I recently installed Slackware, I plan to share my experiences with Apache, MySQL, PHP, etc...
Rate this Entry

Installing a Roller Blog on a Slackware Box (Part 2)

Posted 01-23-2009 at 08:53 PM by ibacsoft

Now, to set the ownership of the Tomcat files and directories:

chown tomcat:tomcat /usr/tomcat (this is for the symbolic link)

chown -R tomcat:tomcat /usr/apache-tomcat-5.5.27 (this is for recursively changing all directories and subdirectories inside the tomcat dir)


The next step is to set the CATALINA_HOME as an environmente variable for /usr/local/tomcat. I opened the /etc/profile file with vi and added the following line:

export CATALINA_HOME=/usr/local/tomcat

then logged out of my Linux box and logged in again, to verify that it was properly set.


To test that the tomcat account could indeed run tomcat, I logged in to my Linux box as a regular user, then typed

#su tomcat

along with the password, and typed the following commands:

#cd $CATALINA_HOME
#/usr/tomcat/bin/startup.sh


Then, the following output appeared:

Using CATALINA_BASE: /usr/tomcat
Using CATALINA_HOME: /usr/tomcat
Using CATALINA_TMPDIR: /usr/tomcat/temp
Using JRE_HOME: /usr/lib/java/jre



I went to Internet Explorer on a Windows PC connected to my LAN, typed http://linuxServerIP:8080 and, voila!! The Welcome to Tomcat page appeared!

After that I typed the following command on my Linux box to shutdown tomcat:

#/usr/tomcat/bin/shutdown.sh

And got the following output on screen:

Using CATALINA_BASE: /usr/tomcat
Using CATALINA_HOME: /usr/tomcat
Using CATALINA_TMPDIR: /usr/tomcat/temp
Using JRE_HOME: /usr/lib/java/jre



I tried to access the tomcat welcome page again, and I couldnīt, so that confirms the tomcat service is indeed shutdown.

NOTE: I used Internet Explorer to test tomcat, and when I shutdown the server tried to reload the welcome page and it showed up again. That's strange, because I already had shutdown tomcat! To be really sure, I closed Internet Explorer, then opened it again and typed the url to the tomcat welcome page. This time it didnīt show up, so I guess thatīs an issue with the Internet Explorer cache.


How to start/stop Tomcat automatically
In Slackware, when you want Tomcat to start/stop at system bootup/shutdown, you need to make a script and put it in /etc/rc.d. If you look at the /etc/rc.d content, youīll see a lot of rc.something scripts for all the services that start/stop along with the system. Thereīs a script for apache, called rc.httpd, for example. For Tomcat, I used the Tomcat5.sh script in $CATALINA_HOME/bin/jsvc-src/native. I had to modify the script to use it on my Linux box. First you need to copy the Tomcat5.sh script to /etc/rc.d with the following command:

#cp $CATALINA_HOME/bin/jsvc-src/native/Tomcat5.sh /etc/rc.d/rc.tomcat

The name of the script is going to be rc.tomcat, to follow the naming convention as the other scripts in /etc/rc.d. Then you need to open rc.tomcat with:

#vi /etc/rc.d/rc.tomcat

And modify the required lines so it can work in your Linux machine.

The lines you need to edit are in bold:


#!/bin/sh
##############################################################################
#
# Copyright 2004 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##############################################################################
#
# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 please modify the server.xml
# file:
#
# <!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->
# <Connector className="org.apache.catalina.connector.http.HttpConnector"
# port="80" minProcessors="5" maxProcessors="75"
# enableLookups="true" redirectPort="8443"
# acceptCount="10" debug="0" connectionTimeout="60000"/>
#
# That is for Tomcat-5.0.x (Apache Tomcat/5.0)
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/lib/java
CATALINA_HOME=/usr/tomcat
DAEMON_HOME=/usr/tomcat/bin
TOMCAT_USER=tomcat


# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/tomcat

CATALINA_OPTS="-Djava.endorsed.dirs=/usr/tomcat/common/endorsed"CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
case "$1" in
start)
#
# Start Tomcat
#
$DAEMON_HOME/jsvc \
-user $TOMCAT_USER \
-home $JAVA_HOME \
-Dcatalina.home=$CATALINA_HOME \
-Dcatalina.base=$CATALINA_BASE \
-Djava.io.tmpdir=$TMP_DIR \
-wait 10 \
-pidfile $PID_FILE \
-outfile $CATALINA_HOME/logs/catalina.out \
-errfile '&1' \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap
#
# To get a verbose JVM
#-verbose \
# To get a debug of jsvc.
#-debug \
exit $?
;;

stop)
#
# Stop Tomcat
#
$DAEMON_HOME/jsvc \
-stop \
-pidfile $PID_FILE \
org.apache.catalina.startup.Bootstrap
exit $?
;;

*)
echo "Usage tomcat.sh start/stop"
exit 1;;
esac




Then, to test the script, use:

#sh /etc/rc.d/rc.tomcat start

And open a Web browser to check that the Tomcat welcome screen shows up. Now close tomcat with:

#sh /etc/rc.d/rc.tomcat stop

then you need to make the rc.tomcat script executable, so it can run when the system starts/shuts down:

#chmod +x /etc/rc.d/rc.tomcat

now you have to edit the /etc/rc.d/rc.M file. After the Apache initialization, add:

# Start Tomcat:
if [ -x /etc/rc.d/rc.tomcat ]; then
. /etc/rc.d/rc.tomcat start
fi


you have to do the same thing with the /etc/rc.d/rc.K file, to stop Tomcat. Before the Apache shutdown code, add:

# Stop Tomcat:
if [ -x /etc/rc.d/rc.tomcat ]; then
/etc/rc.d/rc.tomcat stop
fi


Now you can reboot your linux machine and check if the tomcat server starts automatically.
Posted in Uncategorized
Views 943 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration