We’ve got some 3rd party service scripts that we’re starting to use, but to configure them properly for our environment, we need to pass them some environment variables. How is this normally done?
The traditional way to handle passing configuration to service daemons launched by /etc/init.d/[service] scripts is to set variables in the /etc/sysconfig/[service] files which are usually sourced by service scripts. For example, the network service sources the file /etc/sysconfig/network.
# egrep '/etc/sysconfig/network($| )' /etc/init.d/network if [ ! -f /etc/sysconfig/network ]; then . /etc/sysconfig/network
Then the network service makes use of any variables set in that config file. To see if a 3rd-party service is already coded to source any config files, try the following:
$ cd /etc/init.d $ egrep -w '^[[:space:]]*(\.|source)' [ServiceName]
An example, using the network service shows that it sources /etc/sysconfig/network, among others (though this grep command won’t make it clear whether the config files are conditionally sourced or always sourced).
$ egrep -w '^[[:space:]]*(\.|source)' /etc/init.d/network . /etc/init.d/functions . /etc/sysconfig/network . /etc/sysconfig/pcmcia . ./network-functions
If there aren’t any sourced config files that can be easily co-opted to setup the desired custom variables, and assuming it is not desired to launch these 3rd-party services manually from rc.local or to modify them at all, then the best option would be to disable the services altogether and create custom launcher/wrapper service script that calls them after setting the appropriate environment variables. The atd or ntpd (/etc/init.d/atd, /etc/init.d/ntpd) service scripts are good simple templates to start with.