1

I made tomcat init.d script used by service like 'service tomcat start'. script is like this.

...
CATALINA_HOME=/opt/tomcat7/default
if [ $UID -eq 0 ]
then
        RUN_COMMAND="runuser -l tomcat -c"
        RUN_TOMCAT_COMMAND="sh $CATALINA_HOME/bin"
else
        RUN_COMMAND="sh "
        RUN_TOMCAT_COMMAND="$CATALINA_HOME/bin"
fi
...
function process_startup() {
        $RUN_COMMAND "$RUN_TOMCAT_COMMAND/startup.sh"
}
...

and CATALINA_HOME and CATALINA_BASE variables are set by making script file '/etc/profile.d/tomcat.sh'. So when I type command env in shell, CATALINA_BASE and CATALINA_HOME are shown like below.

...
CATALINA_HOME=/opt/tomcat7/default
CATALINA_BASE=/var/opt/tomcat7/base
...

So logging as root when I type command 'service tomcat start', tomcat start and CATALINA_BASE is set as '/var/opt/tomcat7/base'. right!. That's natural.

But logging as another user(tomcat) when I type command 'service tomcat start', tomcat start but CATALINA_BASE is not set(if CATALINA_BASE is not set, CATALINA_BASE is same as CATALINA_HOME). So When I write line 'echo $CATALINA_BASE' in the middle of 'catalina.sh', it print blank(means variable is not set). I don't know why catalina.sh cannot see environment variable 'CATALINA_BASE' when logging as non-root user and start init.d script by service. 'CATALINA_BASE' environment variable is set apparently!!

Stephen Choi
  • 70
  • 1
  • 8

1 Answers1

0

Ways to set environment variables under *nix,

  1. User-specific
    Modify the profile file for each user (found in their home directory) and set the environment variables.

  2. Global
    Edit the file: /etc/profile and add those variables.

You can do either one depending on whether you want these variables available to all users or not.

NOTE:
Once you make the changes, disconnect all your terminal sessions and reconnect, so that you can work with the updated variables.

Jenson Jose
  • 532
  • 2
  • 15
  • 33