This is a discussion on java in /etc/init.d script (newbie sa question) within the Linux Administration forums, part of the Linux Forums category; SuSE 8.2 Intel One of our java developers wants to have his app (.jar) start up in a /etc/...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
SuSE 8.2 Intel
One of our java developers wants to have his app (.jar) start up in a /etc/init.d script for run levels 3 and 5 (/etc/init.d/rc{3,5}.d He says the command-line invocation is java -jar hisProg.jar to run in the foreground, or (obviously) java -jar hisProg.jar & to run in the background. I'm willing to experiment with this, but as it's a production app I'd be a lot more comfortable if I was fully versed in what's involved in getting this running as a daemon process. Clues, URLs, or other references greatly appreciated. |
|
|||
|
On Wed, 28 Jan 2004 03:17:04 GMT, Richard wrote:
> SuSE 8.2 Intel > > One of our java developers wants to have his app (.jar) start up in a > /etc/init.d script for run levels 3 and 5 (/etc/init.d/rc{3,5}.d If loaded, you may want to read some of the files found here, try locate /doc/initscripts and cut/paste something like /usr/share/doc/initscripts-7.06 into your browser. You could build a script and use service script_name start/stop/reset Example: http://groups.google.com/advanced_group_search slrnblf7e0.4dt.BitTwister@wb.home in the message id box *linux* in Newsgroup, U need 2 use *, pick English man chkconfig |
|
|||
|
BitTwister@localhost.localdomain wrote...
> On Wed, 28 Jan 2004 03:17:04 GMT, Richard wrote: > > SuSE 8.2 Intel > > > > One of our java developers wants to have his app (.jar) start up in a > > /etc/init.d script for run levels 3 and 5 (/etc/init.d/rc{3,5}.d > > If loaded, you may want to read some of the files found here, try > locate /doc/initscripts > and cut/paste something like > /usr/share/doc/initscripts-7.06 > into your browser. > > You could build a script and use > service script_name start/stop/reset > > Example: > http://groups.google.com/advanced_group_search > slrnblf7e0.4dt.BitTwister@wb.home in the message id box > *linux* in Newsgroup, U need 2 use *, pick English > > man chkconfig Thanks, and I'll look into these. Maybe 'service' turns its arguments into a daemon. Just to be more specific, I'm familiar with init.d scripts. But if java is invoked as I've described (java -jar hisprog.jar) in a startup script, won't it exit after the shell interpreting the script (the #! /bin/sh line) exits? |
|
|||
|
On Wed, 28 Jan 2004 15:02:27 GMT, Richard wrote:
> Thanks, and I'll look into these. > Maybe 'service' turns its > arguments into a daemon. No it does not. > Just to be more specific, I'm familiar with init.d scripts. But if > java is invoked as I've described (java -jar hisprog.jar) in a > startup script, won't it exit after the shell interpreting the script > (the #! /bin/sh line) exits? The script will exit when it completes all the commands in the script. You need a testbed, non production, to test in before going into production. |
|
|||
|
Bit Twister wrote:
> On Wed, 28 Jan 2004 15:02:27 GMT, Richard wrote: > > >>Thanks, and I'll look into these. > > >>Maybe 'service' turns its >>arguments into a daemon. > > > No it does not. > > >>Just to be more specific, I'm familiar with init.d scripts. But if >>java is invoked as I've described (java -jar hisprog.jar) in a >>startup script, won't it exit after the shell interpreting the script >>(the #! /bin/sh line) exits? > > > The script will exit when it completes all the > commands in the script. > > You need a testbed, non production, to test in before going into > production. I take it you're talking about the startup script, not the java app. The Java app will continue until it is finished. Just thought it needed some clarification for the OP. -- Ben M. ---------------- What are Software Patents for? To protect the small enterprise from bigger companies. What do Software Patents do? In its current form, they protect only companies with big legal departments as they: a.) Patent everything no matter how general b.) Sue everybody. Even if the patent can be argued invalid, small companies can ill-afford the typical $500k cost of a law-suit (not to mention years of harassment). Don't let them take away your right to program whatever you like. Make a stand on Software Patents before its too late. Read about the ongoing battle at http://swpat.ffii.org/ ---------------- |
|
|||
|
saint_abroadremove@removehotmail.com wrote...
> Bit Twister wrote: > > On Wed, 28 Jan 2004 15:02:27 GMT, Richard wrote: > > > > > >>Thanks, and I'll look into these. > > > > > >>Maybe 'service' turns its > >>arguments into a daemon. > > > > > > No it does not. > > > > > >>Just to be more specific, I'm familiar with init.d scripts. But if > >>java is invoked as I've described (java -jar hisprog.jar) in a > >>startup script, won't it exit after the shell interpreting the script > >>(the #! /bin/sh line) exits? > > > > > > The script will exit when it completes all the > > commands in the script. > > > > You need a testbed, non production, to test in before going into > > production. Of course. What I think I really need is clarity of the mechanisms involved rather than saying "it seemed to work in testing" and then taking it to production. What happens to the running java invocation after the shell it's running in exits? Does the init process get it? > I take it you're talking about the startup script, not the java app. The > Java app will continue until it is finished. So, in /etc/init.d/myjar (ln'ed to, say, /etc/init.d/rc3.d/S50myjar) with these lines, given correct values for ${JAVA} and {$JARPATH}... #! /bin/bash # the usual /etc/init.d start/stop/etc. script stuff, skipped .... start) echo "Starting myjar..." ${JAVA} -jar ${JARPATH}/myjar.jar & # more of the usual /etc/init.d script stuff, skipped .... # end of script ....myjar.jar will continue executing after the script terminates? Again, I'm just trying to be clear on the mechanism involved rather than just use it without understanding why it works. > Just thought it needed some clarification for the OP. Thank you. |
|
|||
|
On Wed, 28 Jan 2004 18:28:05 GMT, Richard wrote:
> > Of course. What I think I really need is clarity of the mechanisms > involved rather than saying "it seemed to work in testing" and then > taking it to production. The suggestion was so you could see what will happen not just checking your installation/backout procedure. > What happens to the running java invocation after the shell it's > running in exits? Does the init process get it? We cannot see what happens because you did not supply the java code. > Again, I'm just trying to be clear on the mechanism involved rather > than just use it without understanding why it works. Tell you what, create a script "ping_loop" on a test bed, example while [ 0 -eq 0 ] ; do sleep 10 ping -c 1 localhost >> /tmp/ping.log done chmod +x ping_loop then see what happens (ie ps aux | grep myjar) with your myjar init script using start) echo "Starting myjar..." /some/where/ping_loop and /some/where/ping_loop & |
|
|||
|
On Wed, 28 Jan 2004 21:40:24 GMT, Bit Twister wrote:
> On Wed, 28 Jan 2004 18:28:05 GMT, Richard wrote: >> >> Of course. What I think I really need is clarity of the mechanisms >> involved rather than saying "it seemed to work in testing" and then >> taking it to production. > > The suggestion was so you could see what will happen not just checking > your installation/backout procedure. > >> What happens to the running java invocation after the shell it's >> running in exits? Does the init process get it? > > We cannot see what happens because you did not supply the java code. > >> Again, I'm just trying to be clear on the mechanism involved rather >> than just use it without understanding why it works. > > Tell you what, create a script "ping_loop" on a test bed, example > > while [ 0 -eq 0 ] ; do > sleep 10 > ping -c 1 localhost >> /tmp/ping.log > done > > chmod +x ping_loop > > then see what happens (ie ps aux | grep myjar) > > > with your myjar init script using > start) > echo "Starting myjar..." > /some/where/ping_loop > and > /some/where/ping_loop & > PS: forgot to add, I assume the testbed has no other users when you test your myjar with a shutdown -r now |
|
|||
|
BitTwister@localhost.localdomain wrote...
> On Wed, 28 Jan 2004 18:28:05 GMT, Richard wrote: > > > > Of course. What I think I really need is clarity of the mechanisms > > involved rather than saying "it seemed to work in testing" and then > > taking it to production. > > The suggestion was so you could see what will happen not just checking > your installation/backout procedure. Eh? Installation and install backout is a completely different issue than controlling an (obviously already-installed) process via an /etc/init.d script. My question really boils down to this: By design of the boot process, and the way init is designed to process /etc/init.d scripts, can a process that is not a daemon be started and continue to run after the script that invokes it terminates--AND (here's the important part) IF SO, WHY? I'm getting the sense that the answer is: "I'm not really sure how init is supposed to work in the case you've suggested, but here are some ways that you can at least see what the behavior is." That's a good answer, as far as it goes, and I thank you for it. > > What happens to the running java invocation after the shell it's > > running in exits? Does the init process get it? > > We cannot see what happens because you did not supply the java code. I'm not sure it takes much imagination to figure, from my questions, that it's an application whose intended lifetime is at least longer than the /etc/init.d script that invokes it. So, in a practical sense, it doesn't matter what the java code does. > > Again, I'm just trying to be clear on the mechanism involved rather > > than just use it without understanding why it works. > > Tell you what, create a script "ping_loop" on a test bed, example > > while [ 0 -eq 0 ] ; do > sleep 10 > ping -c 1 localhost >> /tmp/ping.log > done > > chmod +x ping_loop > > then see what happens (ie ps aux | grep myjar) > > > with your myjar init script using > start) > echo "Starting myjar..." > /some/where/ping_loop > and > /some/where/ping_loop & I guess the "understand why it works" part got lost in translation. Well, again, that's OK. Thanks very much for your help. |
|
|||
|
On Thu, 29 Jan 2004 05:45:22 GMT, Richard wrote:
> > I'm not sure it takes much imagination to figure, from my questions, > that it's an application whose intended lifetime is at least longer > than the /etc/init.d script that invokes it. > So, in a practical sense, it doesn't matter what the java code does. Yeah, right. You run the ping_loop as suggested and see what happens. |