tags:

views:

326

answers:

2

We have a jboss application server running a webapp. We need to implement a "restart" button somewhere in the UI that causes the entire application server to restart. Our naive implementation was to call our /etc/init.d script with the restart command. This shuts down our application server then restarts it.

However, it appears that when the java process shuts down, the child process running the restart scripts dies as well, before getting to the point in the script where it starts the app server again.

We tried variations on adding '&' to the places where scripts are called, but that didn't help. Is there some where to fire the script and die without killing the script process?

+1  A: 

Try using the nohup command to run something from within the script that you execute via Java. That is, if the script that you execute from Java currently runs this:

/etc/init.d/myservice restart

then change it to do this:

nohup /etc/init.d/myservice restart

Also, ensure that you DO NOT have stdin, stdout, or stderr being intercepted by the Java process. This could cause problems, potentially. Thus, maybe try this (assuming bash or sh):

nohup /etc/init.d/myservice restart >/dev/null 2>&1
Eddie
That would probably work in some cases, but unfortunately not ours. Our server process itself was started with nohup. So to stop it, we need to send SIGINT or SIGTERM. And those propagate down to the restart script despite the nohup. It's a catch-22.
A: 

Set your signal handlers in the restart script to ignore your signal with trap:

trap "" 2 #  ignore SIGINT
trap "" 15 # ignore SIGTERM

After doing this, you'll need to kill your restart script with some other signal when needed, probably SIGKILL.

pra