View Single Post

   
  #2 (permalink)  
Old 01-18-2008, 05:34 AM
IANAL_VISTA
 
Posts: n/a
Default Re: Start scripts under linux

fritz-bayer@web.de (Fritz Bayer) wrote in
news:a9c0aa9e.0411071443.2c6ccf8f@posting.google.c om:

> Hello,
>
> I'm currently installing two java programs to run as a service under
> debian/woody.
>
> I'm familiar with the basic concepts of start scripts under linux. I
> know about the runlevels and the init.d and rcX.d directories.
>
> I finally managed to install the two java start scripts in such a way
> that the java programs would actually stay up runnning.
>
> But for this I had to use the "su" and "nohup" command. And now I'm
> curious about why I have to use these.
>
> If somebody could elaborate a little bit on this and linux services in
> general I would really appreciate it.
>
> I still don't really understand, why my java program would not stay
> alive, when I merely entered the following line into the linux start
> script:
>
> cd /opt/mp/bin
> java -jar myprogram.jar &
>
> Like this the program would not stay up running, even though I could
> start the program by running the linux start script from a remote
> console.
>
> I then read that supposedly the problem is that after the linux start
> script stops all its child processes die and therefore also the java
> command.
>
> Is that true?
>
> However, it's true that merely this line would not make my program
> start at boot time. I had to use the "nohup" and "su" command. This
> worked.
>
> The problem I'm left with now, is that I actually have no controll
> over the timing and sequence in which my programs get executed.
>
> The problem is that the second program needs the first one. So if the
> first one takes too long to start up, the secons one raises an error.
>
> I solved this by starting the first program at the very beginning and
> the second one at the very very end (S01 and S99).
>
> However, now I'm actually depending on a race condition. I do not feel
> very comfortable with this solution.
>
> I would like to know how I can assure that my program actually runs
> after the script finishes? How do I manage dependencies. And why does
> a simple "java myprogram &" not work and need a "nohub" or "su" ??
>
> Fritz
>


I hope the following might works for you or some variation on the theme.
In your first script do some thing ( create a file, open a socket & send a
message, etc) at the very end when it is really ready to run. In the second
script have it start, but wait for the flag from the 1st script before
proceeding with its actual startup code.

Some how I doubt the "su" is really required.

FWIW - the line "java myprogram &" has the java process running "in the
backkground"; BUT it still depend upon its parent process to stay alive.
This is because the background process is a child process of its parent;
the process from which "java myprogram &" was issued. When the parent
process dies the child process gets terminated.

The "nohup" (no hangup) instructs the OS to allow the process to stay alive
after the parent process terminates.
Reply With Quote