Saturday, January 8, 2011

To run Tomcat from the startup.sh



/usr/share/tomcat6/lib vs. /var/lib/tomcat6/lib









Janek, I hope my answer still help you or to anyone else...



To run Tomcat from the startup.sh:



modify /etc/init.d/tomcat6:



Add "run)" option after "try-restart)":




Code:

  try-restart)
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT6_USER --startas "$JAVA_HOME/bin/java" \
>/dev/null; then
$0 start
fi
;;
run)
/usr/share/tomcat6/bin/startup.sh
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 1
;;

Then, at your /usr/share/tomcat6/bin/startup.sh:



CATALINA_BASE=/var/lib/tomcat6; export CATALINA_BASE

CATALINA_HOME=/var/lib/tomcat6; export CATALINA_HOME

CATALINA_TMPDIR=/var/lib/tomcat6/temp; export CATALINA_TMPDIR

exec "$PRGDIR"/"$EXECUTABLE" run "$@"



Note: don't forget to change the "start" to "run" at the last line...



And finally, create a link from /var/lib/tomcat6/bin to /usr/share/tomcat6/bin



That's it...



To start tomcat:

sudo /etc/init.d/tomcat6 run

(if you want to see the log at the console, to stop press CTRL+C)



or



sudo /etc/init.d/tomcat6 run > /tmp/mylog

(if you want to send the output to a file)



This is very useful (at least for me) to be able to have access to the
System.out without having to modify java codes or tomcat configuration
files...