Author: justi9
Date: 2010-01-29 16:31:46 -0500 (Fri, 29 Jan 2010)
New Revision: 3832
Modified:
mgmt/trunk/cumin/python/cumin/tools.py
mgmt/trunk/wooly/python/wooly/server.py
Log:
Check that the web port is bindable before starting the server
Modified: mgmt/trunk/cumin/python/cumin/tools.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/tools.py 2010-01-29 14:43:06 UTC (rev 3831)
+++ mgmt/trunk/cumin/python/cumin/tools.py 2010-01-29 21:31:46 UTC (rev 3832)
@@ -125,6 +125,7 @@
app.init()
server = CuminServer(app, self.config.addr, self.config.port)
+ server.init()
if self.config.ssl:
cpath = os.path.join(self.config.home, "etc",
"cumin.crt")
Modified: mgmt/trunk/wooly/python/wooly/server.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/server.py 2010-01-29 14:43:06 UTC (rev 3831)
+++ mgmt/trunk/wooly/python/wooly/server.py 2010-01-29 21:31:46 UTC (rev 3832)
@@ -1,3 +1,5 @@
+import socket
+
from traceback import print_exc
from datetime import datetime, timedelta
from threading import Thread
@@ -35,6 +37,23 @@
def set_ssl_key_path(self, path):
self.server.ssl_private_key = path
+ def do_init(self):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ try:
+ for i in range(10):
+ try:
+ s.bind((self.addr, self.port))
+ return
+ except socket.error:
+ log.warn("Address %s:%i is taken; retrying",
+ self.addr, self.port)
+ time.sleep(1)
+ finally:
+ s.close()
+
+ raise Exception("Failed to bind to %s:%i" % (self.addr, self.port))
+
def do_start(self):
self.server.start()
self.client_session_expire_thread.start()