• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Ubuntu: env variables and scripting issues

minestrone

More fingers than teeth
Joined
Apr 24, 2008
Messages
17,844
Likes received
990
Thanks received
182
Is there anything different about the way ubuntu deals with env variables in sctipts? I am trying to get tomcat installed and running which is something I have done a thousand times on Solaris.

It relies on JAVA_HOME being set so...

Code:
JAVA_HOME=/opt/java/jdk1.6.0_14
export JAVA_HOME

echo $JAVA_HOME
/opt/java/jdk1.6.0_14

So I kick of the startup script and..

Code:
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
So a quick look at the startup script and..


Code:
# Make sure prerequisite environment variables are set
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  # Bugzilla 37284 (reviewed).
  if $darwin; then
    if [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
      export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
    fi
  else
    JAVA_PATH=`which java 2>/dev/null`
    if [ "x$JAVA_PATH" != "x" ]; then
      JAVA_PATH=`dirname $JAVA_PATH 2>/dev/null`
      JRE_HOME=`dirname $JAVA_PATH 2>/dev/null`
    fi
    if [ "x$JRE_HOME" = "x" ]; then
      # XXX: Should we try other locations?
      if [ -x /usr/bin/java ]; then
        JRE_HOME=/usr
      fi
    fi
  fi
  if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
[B]    echo "1Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
    echo "At least one of these environment variable is needed to run this program"
    exit 1[/B]
  fi
fi
:confused:
 

That was almost what I was doing although they were going for auto startup and I was just hand cranking it.

In the end I just hacked in the export at the top of the startup script which is not perfect but gets it working for now. Do not understand why it just drops the env variables as they are set before calling the script.

Another entry in the hack list.
 
The only thing I can think is that tomcat script is switching to another user and thus using that account's environment instead of yours...but I could be very wrong.
 
I think you are right. I set the JAVA_HOME as myself but have to sudo the tomcat to get it to run.

Strangely it will not let me sudo the export though. :confused:

I think if I let the auto startup run it then I can remove the hack I suppose.

It is my first experience of running a lynux server after years of solaris, thought they would be the same but it is the small changes that confuse me.

Cheers
 
Why you running Tomcat as root? If you need port 80 then run Apache in front.
 
They are completely different.

as a test do
>env

and then
>sudo env

you'll see the difference.

You'll need to either keep the script as it is...which IMHO isn't really a hack. Although I had thought that the current java was really done by a symbolic link...but anyway, or put the env variable into the .profile of the root user.
 

Yes, I thikn that is pretty similar to lilelvis2000's post where you set it up to start at startup and it will not have any issues with users.

I think I am used to running tomcat off solaris servers that have not been rebooted for 5 years.
 
They are completely different.

as a test do
>env

and then
>sudo env

you'll see the difference.

You'll need to either keep the script as it is...which IMHO isn't really a hack. Although I had thought that the current java was really done by a symbolic link...but anyway, or put the env variable into the .profile of the root user.

Yes, that shows up the diff. Going to set up the .profile for the root. cheers
 

Advertisers

Back
Top