[CalendarServer-changes] [12901] CalendarServer/trunk/calendarserver/tap/caldav.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Mar 13 15:26:56 PDT 2014


Revision: 12901
          http://trac.calendarserver.org//changeset/12901
Author:   wsanchez at apple.com
Date:     2014-03-13 15:26:56 -0700 (Thu, 13 Mar 2014)
Log Message:
-----------
Get ReExecService from twext.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2014-03-13 22:26:30 UTC (rev 12900)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2014-03-13 22:26:56 UTC (rev 12901)
@@ -23,7 +23,6 @@
 ]
 
 import os
-import signal
 import socket
 import stat
 import sys
@@ -67,6 +66,8 @@
 from twext.internet.tcp import MaxAcceptTCPServer, MaxAcceptSSLServer
 from twext.python.filepath import CachingFilePath
 from twext.python.log import Logger, LogLevel, replaceTwistedLoggers
+from twext.application.service import ReExecService
+
 from txweb2.channel.http import (
     LimitingHTTPFactory, SSLRedirectRequest, HTTPChannel
 )
@@ -604,58 +605,6 @@
 
 
 
-class ReExecService(MultiService):
-    """
-    A MultiService which catches SIGHUP and re-exec's the process.
-    """
-    log = Logger()
-
-    def __init__(self, pidfilePath, reactor=None):
-        """
-        @param pidFilePath: Absolute path to the pidfile which will need to be
-            removed
-        @type pidFilePath: C{str}
-        """
-        self.pidfilePath = pidfilePath
-        if reactor is None:
-            from twisted.internet import reactor
-        self.reactor = reactor
-        MultiService.__init__(self)
-
-
-    def reExec(self):
-        """
-        Removes pidfile, registers an exec to happen after shutdown, then
-        stops the reactor.
-        """
-        self.log.warn("SIGHUP received - restarting")
-        try:
-            self.log.info("Removing pidfile: {log_source.pidfilePath}")
-            os.remove(self.pidfilePath)
-        except OSError:
-            pass
-        self.reactor.addSystemEventTrigger(
-            "after", "shutdown", os.execv,
-            sys.executable, [sys.executable] + sys.argv
-        )
-        self.reactor.stop()
-
-
-    def sighupHandler(self, num, frame):
-        self.reactor.callFromThread(self.reExec)
-
-
-    def startService(self):
-        self.previousHandler = signal.signal(signal.SIGHUP, self.sighupHandler)
-        MultiService.startService(self)
-
-
-    def stopService(self):
-        signal.signal(signal.SIGHUP, self.previousHandler)
-        MultiService.stopService(self)
-
-
-
 class PreProcessingService(Service):
     """
     A Service responsible for running any work that needs to be finished prior
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140313/27203609/attachment.html>


More information about the calendarserver-changes mailing list