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.
It is recommended to place configuration settings in a configuration in
/etc/sysconfig/<servicename>
which is then read by the init script.Regards
Bram
As of Fedora 16,
service
only acceptsLANG
andTERM
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.
From
man 5 init
:Additionaly you can do
grep env /etc/init/*
to see how is usedThis is my output:
And for a exhaustive example see some of that scripts. Here nginx.conf: