LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 10-26-2006, 12:51 AM   #1
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Rep: Reputation: 0
Why my /etc/profile can't work??


I setup tomcat and I set the JAVA environment variable in /etc/profile. After I restart my computer and start tomcat, it report NO JAVA environment variable was set. I echo $JAVA_HOME and there is nothing to display.

Please help me: why my setting in /etc/profile doesn't work??
 
Old 10-26-2006, 04:08 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i'd guess you've not exported the variable. run "export JAVAHOME=..." not just "JAVAHOME=..." as the later is only held within the scope of the profile script. so when the profile script is finished, the variable is destroyed. export pushes that variable back out to the users login shell.
 
Old 10-26-2006, 09:58 AM   #3
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks at first.

This is my /etc/profile:
Quote:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
PATH=".:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/ X11"
else
PATH=".:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games"
fi

if [ "$PS1" ]; then
if [ "$BASH" ]; then
PS1='\u@\h:\w\$ '
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi

export JAVA_HOME=/usr/lib/j2sdk1.5-sun
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

umask 022
But it doesn't work. When I type "echo $JAVA_HOME", it still display nothing.
 
Old 10-26-2006, 11:28 AM   #4
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Have you tried /etc/environment?
 
Old 10-26-2006, 07:15 PM   #5
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by HappyTux
Have you tried /etc/environment?
Does it add the export to /etc/environment:
Quote:
export JAVA_HOME=/usr/lib/j2sdk1.5-sun
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
 
Old 10-26-2006, 07:24 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Did you logout since making the change. The /etc/profile script is only executed if bash called interactively as a login shell. Are you sure you are using the bash shell? Check your entry in /etc/passwd. Also check that the --nologin option isn't present.

Section 6.2 of the bash info manual details which login scripts are executed, and under which circumstances.
 
Old 10-26-2006, 07:46 PM   #7
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by HappyTux
Have you tried /etc/environment?
I have tried it, but it still doesn't work.
 
Old 10-26-2006, 07:56 PM   #8
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal
Did you logout since making the change. The /etc/profile script is only executed if bash called interactively as a login shell. Are you sure you are using the bash shell? Check your entry in /etc/passwd. Also check that the --nologin option isn't present.

Section 6.2 of the bash info manual details which login scripts are executed, and under which circumstances.
I am sure I am using bash shell.

My /etc/passwd is:
Quote:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13: proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
irc:x:39:39:ircd:/var/run/ircd:/bin/sh
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
Debian-exim:x:102:102::/var/spool/exim4:/bin/false
binary:x:1000:1000:binary,,,:/home/binary:/bin/bash
gdm:x:100:103:Gnome Display Manager:/var/lib/gdm:/bin/false
messagebus:x:101:104::/var/run/dbus:/bin/false
statd:x:104:65534::/var/lib/nfs:/bin/false
identd:x:105:65534::/var/run/identd:/bin/false
haldaemon:x:106:108:Hardware abstraction layer,,,:/var/run/hal:/bin/false
mysql:x:40:1001:MySQL Server:/dev/null:/bin/false
There is no --nologin.

By the way, should the global evironment variables relate to the terminal type? I think they may not be related.

Last edited by binary; 10-26-2006 at 07:58 PM.
 
Old 10-26-2006, 08:10 PM   #9
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by binary
I am sure I am using bash shell.

My /etc/passwd is:


There is no --nologin.

By the way, should the global evironment variables relate to the terminal type? I think they may not be related.
Try them in your ~/.bashrc then that should be getting executed on login just make sure this is set in your ~/.bash_profile.

Code:
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
No need to logout and back in for testing just use source ~/.bashrc to re-read the file in the current shell once everything is set then logout and back in.
 
Old 10-26-2006, 08:29 PM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Does tomcat run as a system user. If that is the case, you wouldn't set ~/.bashr or ~/.profile as a system user doesn't have a home directory. Also, it might be running in a jail. That means that the environment may be cleared out. If you have an /etc/profile.d/ directory, then put your "export
This link may help: http://www-128.ibm.com/developerwork...xw16TomcatCage

On some systems, there is an /etc/profile.d/ directory where you can add system wide shell startup scripts, such as a /etc/profile.d/tomcat.sh script. However, given your /etc/profile script, it doesn't appear to be the case.

I didn't notice a tomcat system user or a regular user in your /etc/passwd file. This may be a RTFM situation where you need to read through the tomcat installaton procedures more carefully.

Last edited by jschiwal; 10-26-2006 at 08:34 PM.
 
Old 10-26-2006, 08:30 PM   #11
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by HappyTux
Try them in your ~/.bashrc then that should be getting executed on login just make sure this is set in your ~/.bash_profile.

Code:
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
No need to logout and back in for testing just use source ~/.bashrc to re-read the file in the current shell once everything is set then logout and back in.
Thank you. What you say is correct. But I let my tomcat auto-run. So, I need set the global environment variables to support it. When tomcat auto-run, the terminate's environment variables isn't initialized. This is mean the .bashrc environment work after tomcat auto-run, so tomcat can't find the evironment variables.
 
Old 10-26-2006, 08:48 PM   #12
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal
Does tomcat run as a system user. If that is the case, you wouldn't set ~/.bashr or ~/.profile as a system user doesn't have a home directory. Also, it might be running in a jail. That means that the environment may be cleared out. If you have an /etc/profile.d/ directory, then put your "export
This link may help: http://www-128.ibm.com/developerwork...xw16TomcatCage

On some systems, there is an /etc/profile.d/ directory where you can add system wide shell startup scripts, such as a /etc/profile.d/tomcat.sh script. However, given your /etc/profile script, it doesn't appear to be the case.

I didn't notice a tomcat system user or a regular user in your /etc/passwd file. This may be a RTFM situation where you need to read through the tomcat installaton procedures more carefully.
I use j2sdk for other applications besides tomcat. So I want to set global environment. But after I edit the /etc/profile and restart my computer, the java global environment doesn't work. I use 'echo $JAVA_HOME', there is nothing to display too. That confused me.

Last edited by binary; 10-26-2006 at 08:52 PM.
 
Old 10-26-2006, 09:49 PM   #13
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Well if everything else is not working then try putting the lines in the file /etc/init.d/bootmisc.sh near the bottom of the file above the exit 0, that is pretty much the last file run before the login happens. If needed sooner due to start up of the Tomcat make a file and put it in the /etc/init.d/ directory and make a symbolic link into the /etc/rc2.d/ directory with a number lower than the one that starts the Tomcat.
 
Old 10-26-2006, 11:47 PM   #14
binary
LQ Newbie
 
Registered: Dec 2005
Distribution: Debian
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by HappyTux
Well if everything else is not working then try putting the lines in the file /etc/init.d/bootmisc.sh near the bottom of the file above the exit 0, that is pretty much the last file run before the login happens. If needed sooner due to start up of the Tomcat make a file and put it in the /etc/init.d/ directory and make a symbolic link into the /etc/rc2.d/ directory with a number lower than the one that starts the Tomcat.
Thank you agian. Well, I give it up. My solution is add the JAVA environment variables to every header of applications startup shell script which use j2sdk.

It will be a puzzle that the /etc/profile doesn't work.
 
Old 10-29-2006, 06:16 AM   #15
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
How does tomcat start. If there is a startup script, that would be a good place to set your JAVA environmental variables, before tomcat is started.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script in /etc/profile.d/ won't won't work!? BlueSpirit Slackware 1 10-15-2006 11:21 AM
JAVA_HOME in /etc/profile doesn't work in GNOME terminal JoseVilla Linux - Newbie 7 04-09-2006 12:52 AM
/etc/profile doesn't work for setting a global PATH ttilt Mandriva 2 04-15-2004 01:27 PM
Mozilla doesn't work for user-profile furryspider Linux - Software 3 02-28-2004 11:15 AM
got ALSA to work in root, need help getting it to work in my user profile ic3 Slackware 2 11-28-2003 10:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 02:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration