Re: setting enviroment variable before deamon starts



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

.



Relevant Pages

  • Re: Confused about init scripts expectations
    ... I am developing a daemon application to handle datalogger ... I have developed the init script that is ... I attempt to start the daemon using the services configuration GUI ... figure is that the EOF signal is not being received by the program. ...
    (Fedora)
  • Re: [opensuse] BASH: has $COLUMNS gone nuts?
    ... You do realize that lines & columns are dynamic values which at least some terminals and login daemons will continuously adjust right? ... What the above shows is that I dragged the corner of my PuTTY window (which was connected to sshd, not every terminal client nor every server daemon does this) making the window a little larger and without issuing any commands, and no possibility that any bashrc or inclusions got executed, the values changed, because the terminal told the daemon and the daemon told it's child processes. ... Try calling them from within a script: ... Although, I would also actually be perverse and say that since the SCO systems predate most others, including ALL linux, that you could actually make the argument that the dwindling remaining production sco boxes in the world are right and the 90 million linux & freebsd & sun boxes are all wrong. ...
    (SuSE)
  • Re: script "chaining"
    ... If a task (such as a report) would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)
  • Debian PHP jabber client deamon
    ... to prevent PHP stopping the script. ... // disconnect from the Jabber server ... Here's the daemon script for running it in Debian. ... # Gracefully exit if the package has been removed. ...
    (comp.lang.php)
  • Re: script "chaining"
    ... bill wrote: ... If a task would take too long to run while attached to the browser, the current system writes the data to a database file. ... The daemon checks that file every 10 seconds and executes the task, writing the data back to database. ... If you take the A out of LAMP you can write a php script like a bash script or a perl script and execute it. ...
    (comp.lang.php)