[CalendarServer-changes] [4113] CalendarServer/trunk/calendarserver/tap/caldav.py
source_changes at macosforge.org
source_changes at macosforge.org
Wed Apr 29 19:58:25 PDT 2009
Revision: 4113
http://trac.macosforge.org/projects/calendarserver/changeset/4113
Author: darla at apple.com
Date: 2009-04-29 19:58:25 -0700 (Wed, 29 Apr 2009)
Log Message:
-----------
Expanded the check for stale sockets to all 3 socket files used by the server (instead of just 1). Also improved the checking mechanism.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2009-04-29 19:57:50 UTC (rev 4112)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2009-04-30 02:58:25 UTC (rev 4113)
@@ -21,6 +21,7 @@
]
import os
+import socket
import stat
import sys
@@ -650,13 +651,6 @@
#
self.log_info("Setting up service")
- # Make sure no old socket files are lying around.
- if (os.path.exists(config.ControlSocket)):
- # See if the file represents an active socket. If not, delete it.
- if (not stat.S_ISSOCK(os.stat(config.ControlSocket).st_mode)):
- self.log_warn("Deleting stale socket file: %s" % config.ControlSocket)
- os.remove(config.ControlSocket)
-
if config.ProcessType == "Slave":
if (
config.MultiProcess.ProcessCount > 1 and
@@ -682,8 +676,11 @@
logObserver = AMPCommonAccessLoggingObserver(mode, id)
elif config.ProcessType == "Single":
+ # Make sure no old socket files are lying around.
+ self.deleteStaleSocketFiles()
+
realRoot = logWrapper
-
+
logObserver = RotatingFileAccessLoggingObserver(
config.AccessLogFile,
)
@@ -805,11 +802,7 @@
processLocalizationFiles(config.Localization)
# Make sure no old socket files are lying around.
- if (os.path.exists(config.ControlSocket)):
- # See if the file represents an active socket. If not, delete it.
- if (not stat.S_ISSOCK(os.stat(config.ControlSocket).st_mode)):
- self.log_warn("Deleting stale socket file: %s" % config.ControlSocket)
- os.remove(config.ControlSocket)
+ self.deleteStaleSocketFiles()
# The logger service must come before the monitor service, otherwise
# we won't know which logging port to pass to the slaves' command lines
@@ -1089,6 +1082,34 @@
return service
+ def deleteStaleSocketFiles(self):
+
+ # Check all socket files we use.
+ for checkSocket in [config.ControlSocket, config.GlobalStatsSocket, config.PythonDirector.ControlSocket] :
+
+ # See if the file exists.
+ if (os.path.exists(checkSocket)):
+ # See if the file represents a socket. If not, delete it.
+ if (not stat.S_ISSOCK(os.stat(checkSocket).st_mode)):
+ self.log_warn("Deleting stale socket file (not a socket): %s" % checkSocket)
+ os.remove(checkSocket)
+ else:
+ # It looks like a socket. See if it's accepting connections.
+ tmpSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ numConnectFailures = 0
+ testPorts = [config.HTTPPort, config.SSLPort]
+ for testPort in testPorts :
+ try:
+ tmpSocket.connect(("127.0.0.1", testPort))
+ tmpSocket.shutdown(2)
+ except:
+ numConnectFailures = numConnectFailures+1
+ # If the file didn't connect on any expected ports,
+ # consider it stale and remove it.
+ if numConnectFailures == len(testPorts):
+ self.log_warn("Deleting stale socket file (not accepting connections): %s" % checkSocket)
+ os.remove(checkSocket)
+
class TwistdSlaveProcess(object):
prefix = "caldav"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090429/33dec99d/attachment.html>
More information about the calendarserver-changes
mailing list