Link to home
Start Free TrialLog in
Avatar of JBurner
JBurner

asked on

Tomcat RC startup script, works manually but not upon boot

OS: Debian Sarge

Tomcat: Tomcat 5.0.28

Script in init.d:
#!/bin/sh
#
# chkconfig: 345 91 35
# description: Starts and TomCat servlet server
#              used to provide servlets servlet service for apache.

# See how we were called.

echo "This is the start of the tomcat script"


TOMCAT_HOME=/usr/local/Java/TomCat

case "$1" in

  start)

        for user in `ls $TOMCAT_HOME | awk '{ print $1; }'` ; do
            su ${user} -c "/usr/local/Scripts/tomcat.sh start"
        done

        ;;
  stop)
        for user in `ls $TOMCAT_HOME | awk '{ print $1; }'` ; do
            su ${user} -c "/usr/local/Scripts/tomcat.sh stop"
        done
        ;;
  restart)
        echo -n "Restarting TomCat server"
        echo ""
        $0 stop
        sleep 5
        $0 start
        ;;
*)
        echo "Usage: tomcat.sh {start|stop|restart}"
        exit 1
esac


Script in /usr/local/Scripts:

#!/bin/sh
#
# chkconfig: 345 91 35
# description: Starts and TomCat servlet server
#              used to provide servlets servlet service for apache.
JAVA_OPTS="-Xincgc -Xms128m -Xmx1024m"
# See how we were called.
TOMCAT_HOME=/usr/local/Java/TomCat

case "$1" in
  start)
        $0 kill
        cd /home/${USER}/Source/WEB-INF/classes
        /usr/local/Scripts/setCLASSPATH.sh "${TOMCAT_HOME}/${USER}/bin/catalina.sh start" > ${TOMCAT_HOME}/${USER}/logs/console.log 2>&1

        ;;
  stop)
        /usr/local/Scripts/setCLASSPATH.sh "${TOMCAT_HOME}/${USER}/bin/catalina.sh stop" > /dev/null

        ;;
  kill)
        kill -9 $(ps U $USER | grep "TomCat" | grep -v "tail" | awk '{print $1}') 2>&1 |cat> /dev/null
        ;;
  restart)
        echo -n "Restarting Tomcat server"
        $0 stop
        sleep 5
        $0 start
        echo ""
        ;;
*)
        echo "Usage: tomcat.sh {start|stop|restart}"
        exit 1
esac




RC updates run:
update-rc.d /etc/init.d/tomcat start 97 2 3 4 5 . stop 97 0 1 6 .


Generel info:

I have a tomcat running for each user on the system, all named after the username and placed in /usr/local/Java/TomCat/*
If I execute the above script manually, all works fine, but with the above given RC update tomcat does not start auto upon boot time.

I have a weird feeling that it is related to the "su" usage in the script, but I am not sure

Input on this subject is very much appreciated =)

The script works fine on Redhat/fedora startup
Avatar of pjedmond
pjedmond
Flag of United Kingdom of Great Britain and Northern Ireland image

>I have a tomcat running for each user on the system

Looks like they are all usign the same configuration file, in which case they all trying to use the same port? As a result, the first will start, and all subsequent ones will fail.

HTH:)
Also there is a fairly high chance (depending on permissions, that the $user concerned will not be able to access the required files (log/configuration) etc.

...and if you expect to have more than 3 or 4 users running tomcat at once, I hope that you have a *very* powerful pc!

HTH:)
If you'd like to see exactly what the script is doing, then just before the su line you could add the line:

echo "At point 1" >> /tmp/mylog
echo ${USER} >> /tmp/mylog

in the startup script. Then check whether the appropriate user exists *WITH ACCESS* to the directory concerned.

HTH:)
Avatar of JBurner
JBurner

ASKER

Thanks for the input, but as I stated, everything works fine when the script is executed manually

Port configuration is in the server.xml file, one for each user, and not running on the same port =)
Log files etc. are located at the tomcat specific for and owned by the user.

I have very powerful servers =) IBM system P

But again thx for your thoughts and ideas
echo "At point 1" >> /tmp/mylog
echo ${USER} >> /tmp/mylog

And the output from these lines when run in the script is? What command line does that give you, and can you type tha line in? (Add as many of these as necessary in order to determine how far through the scripts it gets.)

I suspect that this will highlight the error?...as if the command line is identical, with the same user permissions then it will work.

The only additional thought is that due to the environement at this stage during boot up, it may be necessary to run the command with an & at the end. This may be required in order to make it run in the backgroung rather than 'hang' the script.

Avatar of JBurner

ASKER

Hmm, seems like the system doesn't rekognize the $USER variable, the echo $USER comes back empty before su so no wonder it's unable to start up.

Do you have any thoughts how to deal with this, I thought the $USER variable was global from start
As suspected:)

Next problem:
----------------------8X-----------------
        for user in `ls $TOMCAT_HOME | awk '{ print $1; }'` ; do
            su ${user} -c "/usr/local/Scripts/tomcat.sh start"
        done
----------------------8X-----------------
In this you are setting ${user} to be the name of each of the directories that exist under $TOMCAT_HOME

Can you:

echo "At point 2" >> /tmp/mylog
echo $TOMCAT_HOME >> /tmp/mylog

from within the script before the bit quoted above. If this is wrong, then obviously the users won't be right either!

The problem I suspect is that $TOMCAT_HOME has not been initiated at this stage in the start up. Perhaps change this to a constant earlier in the script?

HTH:)

Avatar of JBurner

ASKER

It is defined at the start of the script as a variable, I can make it a constant and see if that solves the problem.

But let me try to see what it prompts for TOMCAT_HOME, will be back asap
Avatar of JBurner

ASKER

It is returning the correct path /usr/local/Java/TomCat =( so that's not it
If you run this from the command line, then TOMCAT_HOME should be correct, but at boot time, I'm surprised that TOMCAT_HOME is already defined.

Add:

echo `ls $TOMCAT_HOME` >> /tmp/mylog

before the first reference to TOMCAT_HOME

and check that it gives a list of the names that you want to start the process as.

What does it do now when startup occurs. How far does it get, and does it start up any tomcat servers?

I'm still concerned that you do not seem to have a seperate configuration file for eaxh user, as if a port is already in use, then trying to start another tomcat on the same port will fail.

HTH:)



ASKER CERTIFIED SOLUTION
Avatar of pjedmond
pjedmond
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JBurner

ASKER

I'm using jk for apache so it's not a port but a mountpoint on port 80 forwarded to the correct jk mount point via a frameset in apache for each site/tomcat
Avatar of JBurner

ASKER

No need to be concerned =) I've been running this setup for 5 years now and it has worked like a charm. The reason I'm doing it is the classpath definitions on the code my company is producing, longer story =)
Avatar of JBurner

ASKER

echo `ls $TOMCAT_HOME` >> /tmp/mylog before the variable statement TOMCAT_HOME=/usr/local/Java/TomCat gives me a listing of slash
echo `ls $TOMCAT_HOME` >> /tmp/mylog after variable gives me the correct tomcat dir listing, so that seems to be fine

"what does it do when startup occurs" I'm remoting the server so I can't see what is going on in the startup phase, this is on my list, but the particular server I'm working on is hosted elsewhere =)
"does it start up any tomcat servers" nope not a one.

"I'm still concerned that you do not seem to have a seperate configuration file for eaxh user" each user/tomcat has it's own config file jk have it's workers.properties where mount points are bind to port numbers and each user/tomcat have the server.xml file where port numbers for the specific tomcat are specified
Avatar of JBurner

ASKER

*SIGH* Problem was that JAVA_HOME was not set as a global variable using su -c in the boot process, by setting JAVA_HOME in the tomcat RC script everything worked.

As an appreciation of your time helping me troubleshoot pjedmond KI'm gonna give you half the points for the question.
Avatar of JBurner

ASKER

or all ;=)
Many thanks:)