<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2657.73">
<TITLE>Bootstrapping Servers</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>Dear All,</FONT>
</P>

<P><FONT SIZE=2>I have created some code to close all active connections to a server, spawn a new instance of itself and call reactor.stop() to facilitate a remote bootstrap restart of a server. The bootstrapping process takes place through a loader where if passed an option to bootstrap the code pauses for 20 secs to allow the previous process to exit:</FONT></P>

<P><FONT SIZE=2>import sys</FONT>
</P>

<P><FONT SIZE=2>if sys.argv[1] == &quot;--bootstrap&quot; or sys.argv[1] == &quot;-b&quot;:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; print 'bootstrapping'</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; del sys.argv[1]</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; import time</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; time.sleep(20.0)</FONT>
</P>

<P><FONT SIZE=2>from twisted.python.runtime import platformType</FONT>
<BR><FONT SIZE=2>if platformType == &quot;win32&quot;:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; from twisted.scripts.twistw import run</FONT>
<BR><FONT SIZE=2>else:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; from twisted.scripts.twistd import run</FONT>
</P>

<P><FONT SIZE=2>run()</FONT>
</P>

<P><FONT SIZE=2>However the above code does not allow the server to start since twistd complains that the port is in use:</FONT>
</P>

<P><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-] Log opened.</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-] twistd 1.3.0 (C:\Python23\python.exe 2.3.3) starting up</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-] reactor class: twisted.internet.default.SelectReactor</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-] managers.ConnectionManager starting on 12005</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-] Traceback (most recent call last):</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp; File &quot;D:\python projects\programs\zcfscheduler\loader.py&quot;, line 15, in ?</FONT></P>

<P><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp;&nbsp;&nbsp; run()</FONT>
</P>

<P><FONT SIZE=2>&lt;-- snip --&gt;</FONT>
</P>

<P><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp;&nbsp;&nbsp; return getattr(reactor, 'listen'+self.method)(*self.args, **self.kwargs)</FONT></P>

<P><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp; File &quot;C:\Python23\lib\site-packages\twisted\internet\default.py&quot;, line 283, in listenTCP</FONT></P>

<P><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp;&nbsp;&nbsp; p.startListening()</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp; File &quot;C:\Python23\lib\site-packages\twisted\internet\tcp.py&quot;, line 594, in startListening</FONT></P>

<P><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-]&nbsp;&nbsp;&nbsp;&nbsp; raise CannotListenError, (self.interface, self.port, le)</FONT>
<BR><FONT SIZE=2>2005/03/24 17:14 AUS Eastern Daylight Time [-] twisted.internet.error.CannotListenError: Couldn't listen on any:12005: (10048, 'Address already in use').</FONT></P>

<P><FONT SIZE=2>how can i get the server to stop, restart itself and release the port in the process?</FONT>
</P>

<P><FONT SIZE=2>Regards,</FONT>
</P>

<P><FONT SIZE=2>Grant McDonald</FONT>
</P>

</BODY>
<!--[object_id=#infocomp.com#]--><P><FONT face=Arial color=#808080 size=1></FONT>&nbsp;</P>
<P><FONT face=Arial color=#808080 size=1>Important notice: This message is intended for the individual(s) and entity(s) addressed. The information contained in this transmission and any attached, may be confidential and may also be the subject of legal privilege, public interest immunity or legal professional privilege. Any review, retransmission, dissemination or other use of, taking of any action in reliance upon this information by person or entities other than the recipient is prohibited and requires authorization from the sender. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person) you may not copy or deliver this message to anyone. In such cases you should destroy this message and kindly notify the sender by reply email. </FONT></P>
<P><FONT face=Arial color=#808080 size=1>WARNING: Although Infocomp has taken reasonable precautions so that no viruses&nbsp;are present in this e-mail, the company cannot accept responsibility for any loss or damage arising from the use of e-mail attachments.</FONT></P></HTML>