Pregunta

I have the following problem:

I am using Tomcat 6.0.32 and Java JDK 6.0_26. I have installed it successfully and the Tomcat start page is visible in the browser at port 8080.

I have also created $CATALINA_HOME/setenv.sh script and put some webapp-specific environment variables in it (along with the CATALINA_HOME, JAVA_HOME and CLASSPATH).

I have created a new user "tomcat", set a new home directory for him, and also passwd-ed it.

This script is being sourced from within a init script I created to start and stop Tomcat automatically on reboot. I do not use the standart startup.sh and shutdown.sh found in $CATALINA_HOME, but rather then jsvc daemon starter, so I can use port 8080 from a non-root process (Tomcat itself).

The actual problem is that, after restarting Tomcat my webapp does not receive or see the environment variable I set in setenv.sh and so it won't start.

I have tried to put the environment variable definition in various places:

  • .bashrc in the tomcat home directory
  • /etc/init.d/tomcat script
  • $CATALINA_HOME/bin/setenv.sh
  • $CATALINA_HOME/webapps/myapp/META-INF/context.xml

to no avail, after start of Tomcat my webapp does not see the required environment variables.

My question is - what the heck am I doing worng? Any suggsetions? How am I supposed to transfer env vars to an webapp if the setenv.sh does not work? What could make this mechanism faulty (allegedly this is the way to hand env vars to webapps)?

Here is the startup script I worte:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          allfaweb
# Required-Start:    $syslog $apache $apache2 $httpd
# Should-Start:
# Required-Stop:     $syslog $apache $apache2 $httpd
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: ALLFAweb service
### END INIT INFO

ALLFAWEB_BIN=/install/apache-tomcat-6.0.32-allfaweb/bin/jsvc
test -x $ALLFAWEB_BIN || { echo "$ALLFAWEB_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of setenv.sh file and read it
ALLFAWEB_CONFIG=/install/apache-tomcat-6.0.32-allfaweb/bin/setenv.sh
test -r $ALLFAWEB_CONFIG || { echo "$ALLFAWEB_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }


. /etc/rc.status
rc_reset

. /install/apache-tomcat-6.0.32-allfaweb/bin/setenv.sh;


case "$1" in
    start)
        echo -n "Starting ALLFAweb ";
        $ALLFAWEB_BIN \
           -user tomcat \
           -home $JAVA_HOME \
           -Dcatalina.home=$CATALINA_HOME \
           -pidfile $ALLFAWEB_PID \
           -outfile $CATALINA_HOME/logs/catalina.out \
           -errfile $CATALINA_HOME/logs/catalina.err \
           -cp $CLASSPATH org.apache.catalina.startup.Bootstrap

        rc_status -v
        ;;
    stop)
        echo -n "Shutting down ALLFAweb "
        $ALLFAWEB_BIN \
            -stop \
            -pidfile $ALLFAWEB_PID \
            org.apache.catalina.startup.Bootstrap

        rc_status -v
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    status)
        echo -n "Checking for service ALLFAweb ";
        /sbin/checkproc $ALLFAWEB_BIN
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac
rc_exit

The system I am using is a SUSE SP2:

# uname -a
Linux testmachine 3.0.51-0.7.9-default #1 SMP Thu Nov 29 22:12:17 UTC 2012  x86_64 x86_64 x86_64 GNU/Linux

Any help would be highly appreciated! Thanks in advance :)

¿Fue útil?

Solución 2

I found it. Allegedly the reason is that at first I started Tomcat 6 as root, and then changed the ownership of files to user "tomcat". The root process had written files all over the file system wiht the appropriate permissions, that is, the "tomcat" user could not read them.

The default shell of the "tomct" user was /bin/sh and not /bin/bash

I also deleted the files in $CATALINA_HOME/work and renamed the directory to which my custom env var was pointing to (and the env var accordingly).

There were also some logfiles generated from log4j in the / dicrectory, those are gone too and now everything works as expected :)

Thanks for all the feedback, you kept me going during these 3 days of frustration :)

Cheers!

Otros consejos

You should be using system properties and not environment variables. Check the source for Tomcat's bin/daemon.sh script, which passes all of the standard variables to Tomcat when it is launched.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top