-   Linux - Server (
-   -   chkconfig runs script with different PATH values (

dchester11 10-07-2010 07: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 07: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:

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

dchester11 10-07-2010 09: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 10: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 04:00 AM.