Solved

Tomcat RC startup script, works manually but not upon boot

Posted on 2006-06-12
17
371 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:JBurner
  • 9
  • 8
17 Comments
 
LVL 22

Expert Comment

by:pjedmond
ID: 16884120
>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:)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16884138
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:)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16884154
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:)
0
 

Author Comment

by:JBurner
ID: 16884161
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
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16884190
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.

0
 

Author Comment

by:JBurner
ID: 16884272
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
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16884459
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:)

0
 

Author Comment

by:JBurner
ID: 16884592
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
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:JBurner
ID: 16884734
It is returning the correct path /usr/local/Java/TomCat =( so that's not it
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16884812
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:)



0
 
LVL 22

Accepted Solution

by:
pjedmond earned 500 total points
ID: 16884819
Also, as another thought, how do the users know which port their tomcat is on? Could be a bit of a nightmare if they don't know as they won't be able to use it!
0
 

Author Comment

by:JBurner
ID: 16884837
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
0
 

Author Comment

by:JBurner
ID: 16884867
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 =)
0
 

Author Comment

by:JBurner
ID: 16884974
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
0
 

Author Comment

by:JBurner
ID: 16892816
*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.
0
 

Author Comment

by:JBurner
ID: 16892840
or all ;=)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16892847
Many thanks:)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now