LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   chkconfig runs script with different PATH values (http://www.linuxquestions.org/questions/linux-server-73/chkconfig-runs-script-with-different-path-values-836840/)

dchester11 10-07-2010 06:06 PM

chkconfig runs script with different PATH values
 
I have a question regarding the user that chkconfig runs as. My chkconfig script calls some other scripts to start up a tomcat instance. But the secondary scripts use %JAVA_HOME and for some reason the user it's running under doesn't have that defined. I can call the scripts directly as the root or as another user and it works properly. But I added an echo in the script and when chkconfig calls the script it has a much smaller $PATH and no $JAVA_HOME. Any ideas what is happening here??

kbp 10-07-2010 06:40 PM

When using scripts you shouldn't assume that any variables are 'inherited', set them explicitly or source a file that sets them. This is especially true if your startup script is using 'su' to launch a process as another user, by default su will sanitise the environment before executing the script.

Do something like:
Code:

su - tomcat -c ". /home/tomcat/env.sh; /opt/tomcat/bin/tomcatctl start"
cheers

dchester11 10-07-2010 08:14 PM

So even if I have the scripts setup in /etc/profile.d when chkconfig runs scripts and executes a su command, these may not be applied? Oy! This has been making my head explode all day. It seems like you would be able to set system level variables that would always apply. Not the case though?

kbp 10-07-2010 09:36 PM

It's always better to be explicit than to trust in something that may change underneath you


All times are GMT -5. The time now is 09:24 PM.