LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   getting Tomcat to run on boot in Fedora 4 (https://www.linuxquestions.org/questions/linux-newbie-8/getting-tomcat-to-run-on-boot-in-fedora-4-a-412515/)

bascule 02-07-2006 04:03 AM

getting Tomcat to run on boot in Fedora 4
 
Hi

I've installed Tomcat and Java successfully on my Fedora Core 4 system. I can run startup.sh and see the default Tomcat page on 127.0.0.1:8080.

I now want Tomcat to run on boot, so I've been looking around at how to do this and I've ended up doing the following:

1. Added the following lines to /etc/rc.d/rc.local:

#start Tomcat
sh /home/phil/apache-tomcat-5.5.15/bin/startup.sh


2. Created a symbolic link called "K06tomcat" in /etc/rc.d/rd5.d which points to "/home/phil/apache-tomcat-5.5.15/bin/shutdown.sh" - the idea here is that this gets called on shutdown to stop Tomcat - actually, this is a side issue, is this an appropriate way to do this? - I picked the lowest number available (i.e. from K01, K02...) to name the link with hoping it would get called as soon as possible.



3. Added the following lines to /etc/profile (above the already existing 'export' command):

JAVA_HOME=/usr/java/jdk1.5.0_06
CATALINA_HOME=/home/phil/apache-tomcat-5.5.15


4. Added the following line to ~/.bash_profile:

export JAVA_HOME=/usr/java/jdk1.5.0_06


When Fedora starts up, I get the error message complaining that "neither JAVA_HOME nor JRE_HOME" are defined - this comes from setclasspath.sh, so somehow the environment variables are not being set by either of the two scripts before this is executed, or it's not 'in scope' or something?

For the record, if I hardcode JAVA_HOME in to the top of setclasspath.sh, Tomcat works ok on boot, but I don't want to do that, I want it to use the environment variables.

barrulus 02-07-2006 08:52 AM

use the following:
(save this as /etc/init.d/tomcat)
[snip]
#!/bin/sh
# chkconfig: 3 90 90
# description:Tomcat JSP server
export JAVA_HOME=/usr/local/java
export CATALINA_OPTS="-Xms128m -Xmx756m -Djava.awt.headless=true"
rm -rf /usr/local/tomcat/work/Catalina/localhost/mimecast
case "$1" in
start)
echo -n "Starting Tomcat:"
cd /usr/local/tomcat/bin/
./startup.sh
echo
;;
stop)
echo -n "Stopping Tomcat"
cd /usr/local/tomcat/bin/
./shutdown.sh
echo
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage:$0{start|stop|restart}"
exit 1
esac
exit 0
[/snip]

Ok, in this startup script I have specified what my java environment variable is (/usr/local/java) as I do not use the default system java.
I install java into /usr/java/j2sdk etc, then symlink to /usr/local/java as that way I can add new java, change my symlink, test and if not good just chnage the symlink again...

export CATALINA_OPTS="-Xms128m -Xmx756m -Djava.awt.headless=true"
This line says: run with 128MB RAM, but use a MAX of 756MB RAM, and that it must run as a daemon.


You will also not that I (again, symlink is your friend) symlink /usr/local/tomcat to /usr/local/jakarta_tomcat....etc
Again this is so I can upgrade tomcat with a very very short downtime and very easy rollback in the advent of a problem.

Don't forget to add tomcat to your startup using chkconfig (chkconfig --add tomcat; chkconfig --level 3 tomcat on) , and don't forget to change the permissions of the file /etc/init.d/tomcat, this must be 755 (chmod 755 /etc/init.d/tomcat)

I hope this helps.

bascule 02-07-2006 11:57 AM

That's worked really well, thanks.

Also, I like the use of the symlinks - that's neat solution to changing versions of java/tomcat etc.

Thanks a lot!


All times are GMT -5. The time now is 11:26 AM.