[Checkins] SVN: zc.monitor/trunk/src/zc/monitor/ re-create Unix domain sockets when binding,
Fred Drake
cvs-admin at zope.org
Fri Apr 27 16:16:14 UTC 2012
Log message for revision 125352:
re-create Unix domain sockets when binding,
to avoid losing the monitor on alternating restarts
Changed:
U zc.monitor/trunk/src/zc/monitor/CHANGES.txt
U zc.monitor/trunk/src/zc/monitor/__init__.py
U zc.monitor/trunk/src/zc/monitor/tests.py
A zc.monitor/trunk/src/zc/monitor/unix-sockets.txt
-=-
Modified: zc.monitor/trunk/src/zc/monitor/CHANGES.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/CHANGES.txt 2012-04-27 16:15:35 UTC (rev 125351)
+++ zc.monitor/trunk/src/zc/monitor/CHANGES.txt 2012-04-27 16:16:11 UTC (rev 125352)
@@ -2,11 +2,21 @@
Change History
==============
+0.3.1 (2012-04-27)
+------------------
+
+- When binding the monitor to a Unix-domain socket, remove an existing
+ socket at the same path so the bind is successful. This may affect
+ existing usage with respect to zopectl debug behavior, but will be
+ more predictable.
+
+
0.3.0 (2011-12-12)
------------------
- Added a simplified registration interface.
+
0.2.1 (2011-12-10)
------------------
@@ -25,6 +35,7 @@
- Add the "MORE" mode so commands can co-opt user interaction
+
0.1.2 (2008-09-15)
------------------
@@ -32,11 +43,13 @@
caused errors to get logged when users closed connections before
giving commands.
+
0.1.1 (2008-09-14)
------------------
- Bugfix: fixed and added test for regression in displaying tracebacks.
+
0.1.0 (2008-09-14)
------------------
Modified: zc.monitor/trunk/src/zc/monitor/__init__.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/__init__.py 2012-04-27 16:15:35 UTC (rev 125351)
+++ zc.monitor/trunk/src/zc/monitor/__init__.py 2012-04-27 16:16:11 UTC (rev 125352)
@@ -14,7 +14,7 @@
"""Zope 3 Monitor Server
"""
-import errno, logging, traceback, socket
+import errno, logging, os, stat, traceback, socket
import zope.component
@@ -91,6 +91,10 @@
elif isinstance(address, basestring):
#a unix domain socket string is passed
ourAddress = address
+ if os.path.exists(ourAddress):
+ m = os.stat(ourAddress)
+ if stat.S_ISSOCK(m.st_mode):
+ os.unlink(ourAddress)
try:
global last_listener
@@ -99,6 +103,9 @@
if e.args[0] == errno.EADDRINUSE:
# Don't kill the process just because somebody else has our port.
# This might be a zopectl debug or some other innocuous problem.
+ # (Existing Unix-domain sockets are removed before binding, so
+ # this doesn't work that way for those. Use a separate offline
+ # configuration in that case.)
logging.warning(
'unable to start zc.monitor server because the address %s '\
'is in use.',
Modified: zc.monitor/trunk/src/zc/monitor/tests.py
===================================================================
--- zc.monitor/trunk/src/zc/monitor/tests.py 2012-04-27 16:15:35 UTC (rev 125351)
+++ zc.monitor/trunk/src/zc/monitor/tests.py 2012-04-27 16:16:11 UTC (rev 125352)
@@ -13,9 +13,16 @@
##############################################################################
import doctest
+import sys
+import unittest
def test_suite():
- return doctest.DocFileSuite(
- 'README.txt',
- optionflags=doctest.NORMALIZE_WHITESPACE,
- )
+ suite = unittest.TestSuite([
+ doctest.DocFileSuite(
+ 'README.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE,
+ ),
+ ])
+ if not sys.platform.lower().startswith('win'):
+ suite.addTest(doctest.DocFileSuite('unix-sockets.txt'))
+ return suite
Added: zc.monitor/trunk/src/zc/monitor/unix-sockets.txt
===================================================================
--- zc.monitor/trunk/src/zc/monitor/unix-sockets.txt (rev 0)
+++ zc.monitor/trunk/src/zc/monitor/unix-sockets.txt 2012-04-27 16:16:11 UTC (rev 125352)
@@ -0,0 +1,46 @@
+=========================
+Using Unix-domain sockets
+=========================
+
+Passing a string to start causes it to bind to a Unix-domain socket.
+
+Let's set up logging so we can see what's happening:
+
+ >>> import logging
+ >>> import os
+ >>> import stat
+ >>> import time
+ >>> import zc.monitor
+ >>> import zope.testing.loggingsupport
+
+ >>> loghandler = zope.testing.loggingsupport.InstalledHandler(
+ ... None, level=logging.INFO)
+
+Passing a path as the argument to start causes a Unix socket to be bound:
+
+ >>> path = "testing.sock"
+
+ >>> zc.monitor.start(path)
+ 'testing.sock'
+
+ >>> m1 = os.stat(path)
+ >>> stat.S_ISSOCK(m1.st_mode)
+ True
+
+Attempting to start the monitor at the same path again succeeds, but
+causes a new socket to be created:
+
+ >>> zc.monitor.start(path)
+ 'testing.sock'
+
+ >>> m2 = os.stat(path)
+ >>> stat.S_ISSOCK(m2.st_mode)
+ True
+
+ >>> m1.st_ino == m2.st_ino
+ False
+
+Clean up:
+
+ >>> os.unlink(path)
+ >>> loghandler.uninstall()
Property changes on: zc.monitor/trunk/src/zc/monitor/unix-sockets.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
More information about the checkins
mailing list