This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Tomcat daemon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Tomcat daemon" Watch "Tomcat daemon" New topic
Author

Tomcat daemon

Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Trying to run Tomcat 5 as a daemon
My configurations
OS: Red Hat Linux 8
Run Level = 5
Environment Vars:
$JAVA_HOME=/usr/local/java
$CATALINA_HOME=/usr/local/tomcat/
PATH=$PATH:/$JAVA_HOME/bin
lrwxrwxrwx /etc/rc.d/init.d/tomcat ->/usr/local/tomcat/bin/catalina.sh
lrwxrwxrwx /etc/rc.d/rc5.d/S84tomcat ->/etc/local/tomcat
lrwxrwxrwx /etc/rc.d/rc5.d/K84tomcat ->/etc/local/tomcat
When it boots up tomcat does not start, do not know why...
Anyone?


A. Valentin
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Sorry Path is
PATH=$PATH:$JAVA_HOME/bin
export PATH
I found that it is not being set before catalina.sh runs.
How can configure it to set JAVA_HOME first?
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Set the variables in your cataline.sh.
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Should I remove it from /etc/profile?
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
No, /etc/profile is for your local login environment, meaning that if you want your user to be able to do javac, java etc, you need those.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

I don't think it's a good idea to link the init directly to the tomcat shell scripts. The sell scripts assume some environmental information (such as JAVA_HOME, TOMCAT_HOME and CATALINA_HOME) to be present before they're invoked.
There are some initscripts that manage the job cleaner that come with the RPM distro of Tomcat. However AFAIK there's not (yet) an RPM for Tomcat5, so you'd have to pull a tomcat 4 RPM and plunder it.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Thank you for the replys.
What can I do to ensure those env variables are set so that they are available not only to users but to the daemons as well?
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
My daemon skill is abit rusty. THere is two types of login, one is interactive, and uses by daemon.
The interactive login spanwed by getty is when a real user (adrian.yan) logs in, depends on your distro, most likely your system uses /etc/profile to load your environments.
If you want to start tomcat on start up, the best way is to create a script and put it in /etc/rc.d/init.d (system standard), and start from there. In this way, you can add all those java variabels in the scripts.
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Thanks again for the reply Adrian.
So what you are saying is create a script like where I will set the JAVA_HOME variables and place it in the But don't I have set them at a particular run level?
From what I understand, the files in the rc#.d folder will must have this format S##script_name and the system will translate it as otherwise the files in init.d are not run.
Please clarify...
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Sorry for the confusion:
Here is the basics of a init process (I have debian, you might want to check just to be sure with your distro)
There are different run-level on a linux box, 0 - 6.
0, halt
1, single user
2, multi-user (without NFS, some people say without networking?)
3, full multo-user
4, unused
5, x-window (xdm, gdm, kdm)
6, reboot
Your /etc/inittab tells system program init to start the system and what process at what level. Assuming you want to start your tomcat at level 5 (3 if you don't have x window), you should see a line in your /etc/inittab liek this l5:5:wait:/etc/rc.d/rc 5.
During startup, your rc script will take 5 as the runlevel and enter /etc/rc5.d (rc3.d if no x-window) directory. In that directory, you should see a bunch of KXX*****/SXX****** softlinks that should point to /etc/init.d.
Files start with K means not to run at this level, and S means run at this level. The number after K/S means the relative order that should be run, 99 is the last one I believe.
If you want both your daemon and login shell to have java variables, create a file call /etc/java, put all your java related environment variables in there.
JAVA_HOME=
ANT_HOME=
export XXXXX XXXX
I suggest you create a shutdown/starup script using those system scripts call /etc/init.d/tomcat, in your /etc/rc3.d/S50tomcat -> /etc/init.d/tomcat. That 50 is arbitrary.
In your tomcat script, you should have something like this:
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Adrian,
It works great! I do not know why it did not occur to me to just write a call to the sh scripts with in the startup script ./etc/java/java.sh
Thanks again!
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Ariel: I took a quick look at tomcat. I believe Tomcat 5 actually comes with its own java package that is a daemon service. You might want to take a look at that.
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
Adrian: I did take a look at that, but because I am a Linux newbie I am not familiar with a make tool so the setup instructions seemed cryptic to me
cd $CATALINA_HOME/bin
tar xvfz jsvc.tar.gz
cd jsvc-src
autoconf
./configure
make
cp jsvc ..
cd ..
cd $CATALINA_HOME
./bin/jsvc -Djava.endorsed.dirs=./common/endorsed -cp ./bin/bootstrap.jar \
-outfile ./logs/catalina.out -errfile ./logs/catalina.err \
org.apache.catalina.startup.Bootstrap
Never the less, your previous instructions made it simple enough for me to understand. As I become a bit stronger in Linux I will try using tools like make or even dive into using ANT, which I hear "is like make but without the make rinkles"
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Yes, I highly recomment you learn ANT, it's one of the better tool java community ever build. I use it on Windows, Linux regularly.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tomcat daemon