How do I run strace or ltrace on Tomcat Catalina?

Solution 1:

Unless you need to trace something in the startup process, strace and ltrace both have a -p parameter which attaches to an existing process and begins tracing it. Once tomcat is running, you would get the process id from ps, and run

strace -p 1234 -e open -o outputfile

or

ltrace -p 1234 -e open -o outputfile

where 1234 is the process ID.

The other option, if these "text files" are shell scripts, you should be able to

strace -f -e whatever -o whatever start-tomcat.sh

strace will begin tracing the shell executed to run the script, the -f will tell it to follow as it forks and executes each command. You'll need to filter through the output to figure out which process is which program (using -ff instead of -f will help).

Solution 2:

I don't know what version of Tomcat you are running, so I'm going to take a swag here. It looks like you're running a Tomcat that might be embedded with some other application -- the init scripts seem unusual to me.

However, at the core in a stock Tomcat installation there is $CATALINA_BASE/bin/catalina.sh. That script can be used (and is often time wrapped by other scripts) to start, stop in a daemon configuration or run Tomcat from the console.

If you look at the current 6.x catalina.sh, at line 306 (297 if you are using security manager), you'll see this:

exec "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
... snip ...

Would it be possible to insert your ltrace or strace between exec and "$_RUNJAVA"?

Then you can do ./catalina.sh run and watch the strace (and your Tomcat stdout) scroll by in hopes you find what you are looking for.