[Twisted-Python] Bootstrapping Servers
Harald.Nyman at astrazeneca.com
Harald.Nyman at astrazeneca.com
Thu Mar 24 05:44:23 MST 2005
I do something similar with the help of a shell script - roughly like
#!/bin/sh
touch START_SERVER
while [ -f START_SERVER ]
do
rm START_SERVER
thisDir=`pwd | gawk -F '/' '{print $NF}'`
twistd --pidfile=${thisDir}.pid -noy che.tac > /dev/null &
done
echo Server ${thisDir} stopped.
--------------------------------------------------------------------
# Close connections, tell clients whether we're stopping or restarting,
......
def _stopServer(self, restart):
if restart:
f = open('START_SERVER', 'w')
f.close()
reactor.stop()
sys.exit()
Harald
-----Original Message-----
From: Grant McDonald [mailto:gmcdonald at infocomp.com]
Sent: torsdag, 24 mars 2005 07:38
To: Twisted general discussion (E-mail)
Subject: [Twisted-Python] Bootstrapping Servers
Dear All,
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:
import sys
if sys.argv[1] == "--bootstrap" or sys.argv[1] == "-b":
print 'bootstrapping'
del sys.argv[1]
import time
time.sleep(20.0)
from twisted.python.runtime import platformType
if platformType == "win32":
from twisted.scripts.twistw import run
else:
from twisted.scripts.twistd import run
run()
However the above code does not allow the server to start since twistd
complains that the port is in use:
2005/03/24 17:14 AUS Eastern Daylight Time [-] Log opened.
2005/03/24 17:14 AUS Eastern Daylight Time [-] twistd 1.3.0
(C:\Python23\python.exe 2.3.3) starting up
2005/03/24 17:14 AUS Eastern Daylight Time [-] reactor class:
twisted.internet.default.SelectReactor
2005/03/24 17:14 AUS Eastern Daylight Time [-] managers.ConnectionManager
starting on 12005
2005/03/24 17:14 AUS Eastern Daylight Time [-] Traceback (most recent call
last):
2005/03/24 17:14 AUS Eastern Daylight Time [-] File "D:\python
projects\programs\zcfscheduler\loader.py", line 15, in ?
2005/03/24 17:14 AUS Eastern Daylight Time [-] run()
<-- snip -->
2005/03/24 17:14 AUS Eastern Daylight Time [-] return getattr(reactor,
'listen'+self.method)(*self.args, **self.kwargs)
2005/03/24 17:14 AUS Eastern Daylight Time [-] File
"C:\Python23\lib\site-packages\twisted\internet\default.py", line 283, in
listenTCP
2005/03/24 17:14 AUS Eastern Daylight Time [-] p.startListening()
2005/03/24 17:14 AUS Eastern Daylight Time [-] File
"C:\Python23\lib\site-packages\twisted\internet\tcp.py", line 594, in
startListening
2005/03/24 17:14 AUS Eastern Daylight Time [-] raise CannotListenError,
(self.interface, self.port, le)
2005/03/24 17:14 AUS Eastern Daylight Time [-]
twisted.internet.error.CannotListenError: Couldn't listen on any:12005:
(10048, 'Address already in use').
how can i get the server to stop, restart itself and release the port in the
process?
Regards,
Grant McDonald
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.
WARNING: Although Infocomp has taken reasonable precautions so that no
viruses are present in this e-mail, the company cannot accept responsibility
for any loss or damage arising from the use of e-mail attachments.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 8123 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20050324/5234398e/attachment-0002.bin>
More information about the Twisted-Python
mailing list