Linux Service Command – Using Environment Variables

centosenvironment-variableslinuxredhatservice

I am trying to start a service that requires a env. variable to be set to certain path. I set this variable in "/etc/profile.d/". However when I start this service using the service command, it doesn't work.

man service:

service runs a System V init script in as predictable environment as possible,
removing most environment variables and with current working directory set to /.

So it seems that service is removing my variables. How should I set the variables up to keep them from being removed. Or is that something i should not do.

I could start the service manually using the init-scripts, or even hardcode the path into the script, but I'd like to know how to use it with the service command.

Best Answer

As of Fedora 16, service only accepts LANG and TERM environment variables, everything else gets discarded. So, even if your current {CentOS,RHEL} accepts the variables somehow, be prepared for the future where it does not work any more.

So, hard coding the init script and/or setting up the variables in the daemon settings file itself would be your choices.