Re: setting enviroment variable before deamon starts
- From: Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 21 Jan 2008 09:29:18 +0100
tomb wrote:
On 18 Jan., 16:52, Juha Laiho <Juha.La...@xxxxxx> wrote:
If the env.vars are something that just the daemon should see,
then there are two possibilities. One was already discussed;
make a script that starts the daemon, and that you call during
the system startup (in the rc.local script).
The other possibility is to use "env" command as a helper to start
the daemon; instead of the
/home/progs/ts &
you have above (supposing that's one of the daemons you're starting),
use
env VAR1=val1 VAR2=val2 /home/progs/ts &
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
Thank you very much Juha, It works!
There is one more possibility, I heard about sourcing a file.
But no idea how to do it. Can someone explain in the way as Juha did.
I am newbie to linux.
Got already answer but asking for curiosity.
"Sourceing" refers to the "."-builtin command of a number of shells (iirc the csh calls this "source"):
You put the setting of your environment variables into a file which is kept in a centralized location, e.g. /etc/sysconfig. Your start/stop-script is kept in /etc/init.d with symlinks from /etc/rc.d/rc<runlevel>.d (e.g. /etc/rc.d/rc5.d). The latter file then "sources" the environment variable settings like this:
. /etc/sysconfig/<daemon>
Note that though the /etc/sysconfig/daemon file has to have a proper shell-syntax (you can even include shell functions), "sourcing" is fundamentally different from a simple running of the script, so putting
/etc/sysconfig/<daemon>
into your start/stop-script would not work, as that would start a new shell which would just set the variables in its own context and then exit, leaving the shell that runs the start/stop-script unaware of the settings.
When writing the sysconfig-file you must also be aware that the contents of that script are executed in the context of the start/stop-script, so e.g. an "exit"-command at the end of the sysconfig-file will cause the start/stop-script to exit!
HTH,
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
.
- References:
- setting enviroment variable before deamon starts
- From: tomb
- Re: setting enviroment variable before deamon starts
- From: Juha Laiho
- Re: setting enviroment variable before deamon starts
- From: tomb
- setting enviroment variable before deamon starts
- Prev by Date: RS232 Redirector Program in C using Linux
- Next by Date: Re: RS232 Redirector Program in C using Linux
- Previous by thread: Re: setting enviroment variable before deamon starts
- Next by thread: Timeout timers in an application
- Index(es):
Relevant Pages
|