LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-22-2014, 02:17 AM   #1
Reprovo
Member
 
Registered: Jul 2013
Posts: 37

Rep: Reputation: Disabled
what is the scope of a variable exported In a /init.d startup script


Hi.
I have a small startup script to launch Tomcat 8.0.15 on boot(debian 7.7.0 wheezy) and there are three variables.


export JAVA_HOME=/...

export CATALINA_BASE=/..

export CATALINA_HOME=/..

I have two questions.


1) The script doesn't work If I comment out CATALINA_HOME but It's already set In /etc/profile so I'd like to know why It's necessary.

2) If I type echo $CATALINA_BASE after startup , the variable appears to no longer be set.Does this mean It exists only until the startup script completes ?
 
Old 11-22-2014, 05:02 AM   #2
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
1) The script doesn't work If I comment out CATALINA_HOME but It's already set In /etc/profile so I'd like to know why It's necessary.
You'd have to know what the environmental variable $CATALINA_HOME was set to at the moment the script runs in init, not what it's set to when the boot sequence completes. Have your script begin by echoing the variables prior to setting them, in which case you'll likely find the answer to your question in dmesg.
(suggestion, have the script 'echo "Ummagumma:"$CATALINA_HOME' and then grep dmesg for Ummagumma)
Quote:
2) If I type echo $CATALINA_BASE after startup , the variable appears to no longer be set.
See question #1

Last edited by dijetlo; 11-22-2014 at 05:04 AM.
 
Old 11-22-2014, 08:41 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
Quote:
Originally Posted by Reprovo View Post
Hi.
I have a small startup script to launch Tomcat 8.0.15 on boot(debian 7.7.0 wheezy) and there are three variables.


export JAVA_HOME=/...

export CATALINA_BASE=/..

export CATALINA_HOME=/..

I have two questions.


1) The script doesn't work If I comment out CATALINA_HOME but It's already set In /etc/profile so I'd like to know why It's necessary.
When init starts a script it doesn't have to use the /etc/profile. This is partly a security issue - you don't want the init scripts using something that hasn't been setup yet... or something that is setup for an interactive user from getting imported into the system startup.

Note: this can be invoked by using the "--noprofile" option on bash.

Quote:
2) If I type echo $CATALINA_BASE after startup , the variable appears to no longer be set.Does this mean It exists only until the startup script completes ?
The environment variable only exists as long as the process that declares it is forking new processes. Each of these new processes can inherit the exported variables (doesn't have to, as what is starting the process still has control over the environment passed to the new process).

Once the script stops - it no longer exports. Since login is going through a DIFFERENT path (and the environment may have been purged) the login will not pass that on.
 
Old 11-22-2014, 03:03 PM   #4
Reprovo
Member
 
Registered: Jul 2013
Posts: 37

Original Poster
Rep: Reputation: Disabled
Thanks for the answers !
Makes sense now.Nothing Is appearing In dmesg though.

Last edited by Reprovo; 11-22-2014 at 03:21 PM.
 
Old 11-22-2014, 03:33 PM   #5
nbritton
Member
 
Registered: Jun 2013
Location: Dubuque, IA
Distribution: Red Hat Enterprise Linux, Mac OS X, Ubuntu, Fedora, FreeBSD
Posts: 87

Rep: Reputation: Disabled
When you boot the system init scripts are run before profile. init scripts are executed in there own bash shell, and the exported variables, to my knowledge, only apply to the children that it spawns. Furthermore, profile is only used with login shells, i.e. when you login to the system on the console or from a remote host. You want to put the variable in bashrc, bashrc is run whenever you lunch a shell.

Last edited by nbritton; 11-22-2014 at 04:04 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
(Scope of address) == (scope of variable) kaz2100 Programming 10 01-26-2014 10:54 PM
[SOLVED] [bash] Exported variable gone after end of script? littlebigman Linux - Software 2 04-26-2011 02:33 AM
Add a script to startup/init? licht SUSE / openSUSE 2 07-08-2007 08:53 AM
init.d startup script for familiar pevelius Linux - Laptop and Netbook 2 09-03-2004 11:22 AM
Why won’t this init.d startup script work? dholingw Linux - Software 2 06-08-2004 02:40 PM


All times are GMT -5. The time now is 02:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration