CATALINA_HOME is different in the script?

415 views
Skip to first unread message

in...@princerupertlibrary.ca

unread,
Mar 12, 2014, 2:01:22 PM3/12/14
to isla...@googlegroups.com
Anybody have any idea why CATALINA_HOME would behave this way? I mean, it echos $CATALINA_HOME as the last action before the exit, then if the first command I do after the exit is to echo it again, and it's different... wait, what?

WM

-=-=-=-=-=-=-

# Get standard Java environment variables
if $os400; then
  # -r will Only work on the os400 if the files are:
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  BASEDIR="$CATALINA_HOME"
  . "$CATALINA_HOME"/bin/setclasspath.sh 
else
  if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
    BASEDIR="$CATALINA_HOME"
    . "$CATALINA_HOME"/bin/setclasspath.sh
  else
    echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
    echo "This file is needed to run this program"
    echo "Yes, I am really exiting here and changing $CATALINA_HOME back, somehow."
    exit 1
  fi
fi

--More--(45%)
[6]+  Stopped                 more catalina.sh
wmcduff@Fedora2:/usr/local/fedora/tomcat6/bin$ sudo /usr/local/fedora/tomcat6/bin/startup.sh
Cannot find /usr/share/tomcat6/bin/setclasspath.sh
This file is needed to run this program
Yes, I am really exiting here and changing /usr/share/tomcat6 back, somehow.
wmcduff@Fedora2:/usr/local/fedora/tomcat6/bin$ echo $CATALINA_HOME
/usr/local/fedora/tomcat6
wmcduff@Fedora2:/usr/local/fedora/tomcat6/bin$ 
Message has been deleted
Message has been deleted

in...@princerupertlibrary.ca

unread,
Mar 12, 2014, 2:27:47 PM3/12/14
to isla...@googlegroups.com
Ah, so it's pulling the $CATALINA_HOME from one spot while it's in the script, and another when it's outside the script? That makes sense. So I just need to find where the java environment is pulling it's version of CATALINA_HOME from and change it. Thanks!

(Hmm, I wonder where that is.)

On Wednesday, March 12, 2014 11:07:00 AM UTC-7, Ernie Gillis wrote:
scratch my earlier post. ... loooooong day for me

in order for the environment variable to be persistent, don't you need to do a "setenv" or something? I don't think the variables stay set in the environment once you leave the script without a special method to keep them as environment variables

Ernie Gillis

unread,
Mar 12, 2014, 2:29:11 PM3/12/14
to isla...@googlegroups.com
OK. So I posted twice before, but deleted to remove clutter.

Your shell script needs to make sure to tell your shell (bash, ksh, etc) that your variables are environment variables. Otherwise, once the script finishes, all variable adjustments are lost. Setting the environment variable properly as an environment variable will keep it's value persistently.

For any variable to remain persistent, you need to "export" it ... example:
# begin if statement
if $os400 then
  # set a variable
  CATALINA_HOME=/path/to/my/catalina/service
  #export a variable
  export CATALINA_HOME
fi
#end script

in...@princerupertlibrary.ca

unread,
Mar 12, 2014, 3:57:00 PM3/12/14
to isla...@googlegroups.com
I'm more curious about where this script is pulling it's value from. It has to be set in a preference or properties file somewhere, and if I change it in catalina.sh, I'll likely have similar problems in other files. If I can find the source, I'll be set. I've checked ~/.profile, ~/.bash-profile and /etc/init.d/tomcat6, and they're all pointing correctly. Has to be somewhere else...

WM

Ernie Gillis

unread,
Mar 12, 2014, 4:20:04 PM3/12/14
to isla...@googlegroups.com
It is kind of shell / platform dependent.
I'm running CentOS with a "bash" shell. For that, it's set in individual user accounts as you log in.

My home directory has:
.bash_profile
.bashrc

I set my variables in the ".bash_profile" file. They're both technically shell scripts. The ".bash_profile" loads the ".bashrc" script. There are others there, too, but that's the two commons ones I work with.

There are other places, but that's the safest to do on your individual session when you're logged in to the machine.

My ".bash_profile" file has a contents of:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin


I've continually added to that file for more environment variables, like:
export ANT_HOME=/usr/local/apache-ant
export ANT=$ANT_HOME/bin
export FEDORA_HOME=/usr/local/fedora

export CATALINA_HOME=$FEDORA_HOME/base/
# Etcetera


in...@princerupertlibrary.ca

unread,
Mar 12, 2014, 5:17:59 PM3/12/14
to isla...@googlegroups.com
My .profile file has "export CATALINA_HOME=/usr/local/fedora/tomcat6" line in it. I don't have a .bash_profile file, though I do have .bashrc. I tried putting it in there, but no change. Must be something else taking priority.

Ernie Gillis

unread,
Mar 12, 2014, 6:48:20 PM3/12/14
to isla...@googlegroups.com
If you're wanting "CATALINA_HOME" to be a different value.. I'd set it in the ".profile" file.
You could even put all the logic there with the "if statement" and all.

What happens, if the ".profile" file is similar to my ".bash_profile" file, then loads the ".bashrc" first. After the ".bashrc" gets loaded, the remainder of the ".profile" file continues. In your case, if ".bashrc" is where you customized your "CATALINA_HOME", it gets set there. Then, ".profile" continue and re-assigns the value for "CATALINA_HOME"

in...@princerupertlibrary.ca

unread,
Mar 12, 2014, 7:18:08 PM3/12/14
to isla...@googlegroups.com
I did have it in .profile before. Problem is it's not being picked up by the script for some reason. My theory is that I (or the installer) set it somewhere else which is later in sequence and taking the priority when a script is being run. echo $CATALINA_HOME as a command results in /usr/local/fedora/tomcat6, but in the script it echoes as /usr/share/tomcat6. Not sure where it's getting that second value from, but it must be some file...

Peter .

unread,
Mar 12, 2014, 7:57:10 PM3/12/14
to isla...@googlegroups.com
I make life easy for myself by setting the value in either /etc/environment (for Ubuntu) or /etc/profile.d/fedora.env (for RedHat) to ensure everyone is running the same values. Overriding it in the .profile files only confuses things and should only be done if you really need to do it.

Ernie Gillis

unread,
Mar 13, 2014, 9:16:36 AM3/13/14
to isla...@googlegroups.com
Peter... true.... I'm on a shared system though, and others shouldn't have the access to the the processes. Have readme docs to explain if they do need it and process a request to ask for it... but that's my environment ;)

Alex Garnett

unread,
Mar 13, 2014, 11:14:17 AM3/13/14
to isla...@googlegroups.com
Yeah, I do seem to recall running into the same issue on CentOS where the $CATALINA_HOME variable wasn't being exported correctly -- pretty sure I had to put it in .bash_profile too.

Gervais de Montbrun

unread,
Mar 13, 2014, 12:21:57 PM3/13/14
to isla...@googlegroups.com
On every OS where I install fedora, I make a fedora.sh file and put it in /etc/profile.d. It contains all the variables we need to set for tomcat/fedora to run properly. I’ve had no issues since doing so with CentOS, RHEL, Ubuntu, SLES, Debian, Oracle Linux, Open Suse…

Cheers,
Gervais

--
You received this message because you are subscribed to the Google Groups "islandora" group.
To unsubscribe from this group and stop receiving emails from it, send an email to islandora+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages