Originally Posted by Reprovo
I have a small startup script to launch Tomcat 8.0.15 on boot(debian 7.7.0 wheezy) and there are three variables.
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.
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.