<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How to launch your Java™ RMI server and keep it running on Unix.</title>
	<atom:link href="http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/</link>
	<description>Java Jiggle. See what's shaking.</description>
	<pubDate>Wed, 03 Dec 2008 20:33:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Javajiggler</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-43</link>
		<dc:creator>Javajiggler</dc:creator>
		<pubDate>Mon, 25 Feb 2008 00:36:08 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-43</guid>
		<description>Josh,
You are right.  The above script demonstrates how to restart the java server in case rmiregistry has crashed.   It will not do anything in case the java server crashed.
We will need a separate script “startJavaServer” to respawn the java server.  Something like this should do the trick:

#!/bin/sh
done=0
while [ "$done" -eq 0 ]
do
        java &#38;
        jvmPID=$!
        trap "kill -TERM $jvmPID;done=1" TERM
        wait $jvmPID
        echo "respawning JVM"
done
kill -TERM $jvmPID
echo "Out of the loop!!"

Note, we will need to change "kill -9 $javaServerPID" to "kill -TERM $javaServerPID" in the previous script.
I hope that helps.
Java Jiggler</description>
		<content:encoded><![CDATA[<p>Josh,<br />
You are right.  The above script demonstrates how to restart the java server in case rmiregistry has crashed.   It will not do anything in case the java server crashed.<br />
We will need a separate script “startJavaServer” to respawn the java server.  Something like this should do the trick:</p>
<p>#!/bin/sh<br />
done=0<br />
while [ "$done" -eq 0 ]<br />
do<br />
        java &amp;<br />
        jvmPID=$!<br />
        trap &#8220;kill -TERM $jvmPID;done=1&#8243; TERM<br />
        wait $jvmPID<br />
        echo &#8220;respawning JVM&#8221;<br />
done<br />
kill -TERM $jvmPID<br />
echo &#8220;Out of the loop!!&#8221;</p>
<p>Note, we will need to change &#8220;kill -9 $javaServerPID&#8221; to &#8220;kill -TERM $javaServerPID&#8221; in the previous script.<br />
I hope that helps.<br />
Java Jiggler</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-21</link>
		<dc:creator>Josh</dc:creator>
		<pubDate>Thu, 14 Feb 2008 02:46:31 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-21</guid>
		<description>Maybe I am dense but what happens if the java server dies... glancing at this code looks like it would just stay dead.</description>
		<content:encoded><![CDATA[<p>Maybe I am dense but what happens if the java server dies&#8230; glancing at this code looks like it would just stay dead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JavaJiggler</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-11</link>
		<dc:creator>JavaJiggler</dc:creator>
		<pubDate>Mon, 14 Jan 2008 16:31:04 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-11</guid>
		<description>Armin that’s a good point.  You are right, that if the RMI registry crashes, the java servers need to be reset.

This can be acomplished by launching the rmi registry and the java server(s) in one script.

1. The idea is that the rmi sever will be launched first.
2. The java rmi server will be launched next.
3. The launch script will than block using a wait command to check if rmi registry terminates.
4. If wait unblocks, that means that rmi registry terminated.  When this happens, kill the java server(s) and repeat steps 1-3.

Below is a sample script.  You can tested it by killing the rmi registry and see it respawn both rmi registry and a java server.

Here is a sample: (Note: this should work but has not been tested for syntax)

#!/bin/sh

#kick off the rmi registry
./rmiRegistry &#38;

#store the PID of the RMI registry
rmiRegistryPID=$! 
echo Started RMI registry with PID= $rmiRegistryPID"

#kick off the java server in a script
./startJavaServer &#38;

#store PID for java server
javaServerPID=$!
echo Started Java server with PID= $javaServerPID"

While [ 1 ]
do
	wait $rmiRegistryPID
	echo "RMI Registry (PID=$rmiRegistryPID ) terminated..."

	kill -9 $javaServerPID
	echo "Terminated Java Server"

	./rmiRegistry &#38;
	rmiRegistryPID=$!	
	echo "Respawned RMI registry with PID= $rmiRegistryPID"

	./startJavaServer &#38;
	javaServerPID=$!
	echo "Respawned Java server with PID= $javaServerPID"
done</description>
		<content:encoded><![CDATA[<p>Armin that’s a good point.  You are right, that if the RMI registry crashes, the java servers need to be reset.</p>
<p>This can be acomplished by launching the rmi registry and the java server(s) in one script.</p>
<p>1. The idea is that the rmi sever will be launched first.<br />
2. The java rmi server will be launched next.<br />
3. The launch script will than block using a wait command to check if rmi registry terminates.<br />
4. If wait unblocks, that means that rmi registry terminated.  When this happens, kill the java server(s) and repeat steps 1-3.</p>
<p>Below is a sample script.  You can tested it by killing the rmi registry and see it respawn both rmi registry and a java server.</p>
<p>Here is a sample: (Note: this should work but has not been tested for syntax)</p>
<p>#!/bin/sh</p>
<p>#kick off the rmi registry<br />
./rmiRegistry &amp;</p>
<p>#store the PID of the RMI registry<br />
rmiRegistryPID=$!<br />
echo Started RMI registry with PID= $rmiRegistryPID&#8221;</p>
<p>#kick off the java server in a script<br />
./startJavaServer &amp;</p>
<p>#store PID for java server<br />
javaServerPID=$!<br />
echo Started Java server with PID= $javaServerPID&#8221;</p>
<p>While [ 1 ]<br />
do<br />
	wait $rmiRegistryPID<br />
	echo &#8220;RMI Registry (PID=$rmiRegistryPID ) terminated&#8230;&#8221;</p>
<p>	kill -9 $javaServerPID<br />
	echo &#8220;Terminated Java Server&#8221;</p>
<p>	./rmiRegistry &amp;<br />
	rmiRegistryPID=$!<br />
	echo &#8220;Respawned RMI registry with PID= $rmiRegistryPID&#8221;</p>
<p>	./startJavaServer &amp;<br />
	javaServerPID=$!<br />
	echo &#8220;Respawned Java server with PID= $javaServerPID&#8221;<br />
done</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: celpjefscycle</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-10</link>
		<dc:creator>celpjefscycle</dc:creator>
		<pubDate>Sat, 12 Jan 2008 09:16:36 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-10</guid>
		<description>Thanks for information. 
many interesting things 
Celpjefscylc</description>
		<content:encoded><![CDATA[<p>Thanks for information.<br />
many interesting things<br />
Celpjefscylc</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: armin Kupczok</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-8</link>
		<dc:creator>armin Kupczok</dc:creator>
		<pubDate>Wed, 12 Dec 2007 14:04:54 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-8</guid>
		<description>The scenario above must be inverted. The problem occurs if RMIRegistry crashes. Then RMIServer must restart in order to rebind its stubs after RMIRegistry restart.</description>
		<content:encoded><![CDATA[<p>The scenario above must be inverted. The problem occurs if RMIRegistry crashes. Then RMIServer must restart in order to rebind its stubs after RMIRegistry restart.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: armin Kupczok</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-7</link>
		<dc:creator>armin Kupczok</dc:creator>
		<pubDate>Tue, 11 Dec 2007 18:41:28 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-7</guid>
		<description>We also need to keep rmiregistry and rmiserver running. I think option 4 works well. But there is one point which I dont know how to solve it. If either RMIServer or RMIRegistry crashes both of them must be restarted. So if only RMIServer crashes, RMIRegistry must be restarted and then RMIServer must be started (rebinding). Is there a solution for that problem</description>
		<content:encoded><![CDATA[<p>We also need to keep rmiregistry and rmiserver running. I think option 4 works well. But there is one point which I dont know how to solve it. If either RMIServer or RMIRegistry crashes both of them must be restarted. So if only RMIServer crashes, RMIRegistry must be restarted and then RMIServer must be started (rebinding). Is there a solution for that problem</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tolik</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-2</link>
		<dc:creator>tolik</dc:creator>
		<pubDate>Sat, 10 Nov 2007 20:04:56 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-2</guid>
		<description>This perl script can be started with "nohup" command.  In this example instead of using "sleep 3" and "sleep 6" you can put whatever processes you want (and as many as you want, just keep increasing the list.  when process dies, it gets imedeatly restarted.
NOTE: you can take out print statment, its only for demonstration.

------------------------------------
#!/bin/perl

@cmds=("sleep 3", "sleep 6");

use threads;
sub restart_pid {
	my ($pname)=@_;
	do { my $pid=`$pname &#38;`; print "$pname restarted,time=".time."\n"; }
	while waitpid($pid, 0);
}

foreach $i (@cmds) { threads-&#62;create(\&#38;restart_pid, $i); };
sleep;
-----------------------------</description>
		<content:encoded><![CDATA[<p>This perl script can be started with &#8220;nohup&#8221; command.  In this example instead of using &#8220;sleep 3&#8243; and &#8220;sleep 6&#8243; you can put whatever processes you want (and as many as you want, just keep increasing the list.  when process dies, it gets imedeatly restarted.<br />
NOTE: you can take out print statment, its only for demonstration.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
#!/bin/perl</p>
<p>@cmds=(&#8221;sleep 3&#8243;, &#8220;sleep 6&#8243;);</p>
<p>use threads;<br />
sub restart_pid {<br />
	my ($pname)=@_;<br />
	do { my $pid=`$pname &amp;`; print &#8220;$pname restarted,time=&#8221;.time.&#8221;\n&#8221;; }<br />
	while waitpid($pid, 0);<br />
}</p>
<p>foreach $i (@cmds) { threads-&gt;create(\&amp;restart_pid, $i); };<br />
sleep;<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: javajiggle</title>
		<link>http://javajiggle.com/2007/11/06/how-to-launch-your-java-server-and-keep-it-running-on-unix/#comment-3</link>
		<dc:creator>javajiggle</dc:creator>
		<pubDate>Sat, 10 Nov 2007 16:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://javajiggle.com/?p=8#comment-3</guid>
		<description>This is very good solution.   However, this will not restart a Java process if a server power cycled.
</description>
		<content:encoded><![CDATA[<p>This is very good solution.   However, this will not restart a Java process if a server power cycled.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
