[Buildbot-commits] buildbot/buildbot/scripts reconfig.py, NONE, 1.1 runner.py, 1.45, 1.46

Brian Warner warner at users.sourceforge.net
Fri Nov 24 08:23:29 UTC 2006


Update of /cvsroot/buildbot/buildbot/buildbot/scripts
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv27286/buildbot/scripts

Modified Files:
	runner.py 
Added Files:
	reconfig.py 
Log Message:
[project @ enhance 'buildbot sighup' to show all related twistd.log lines. Also rename it to 'buildbot reconfig'. This addresses half of SF#1517975]

Original author: warner at lothar.com
Date: 2006-11-24 08:21:21

--- NEW FILE: reconfig.py ---

import os, signal
from twisted.internet import reactor, task
from twisted.protocols.basic import LineOnlyReceiver

class FakeTransport:
    disconnecting = False

class LogWatcher(LineOnlyReceiver):
    POLL_INTERVAL = 0.1
    delimiter = "\n"

    def __init__(self, finished):
        self.poller = task.LoopingCall(self.poll)
        self.in_reconfig = False
        self.finished_cb = finished
        self.transport = FakeTransport()
        

    def start(self, logfile):
        try:
            self.f = open(logfile, "rb")
            self.f.seek(0, 2)
            self.poller.start(self.POLL_INTERVAL)
        except IOError:
            print "Unable to follow %s" % logfile
            return False
        return True

    def finished(self, success):
        self.in_reconfig = False
        self.finished_cb(success)

    def lineReceived(self, line):
        if "loading configuration from" in line:
            self.in_reconfig = True
        if self.in_reconfig:
            print line
        if "I will keep using the previous config file" in line:
            self.finished(False)
        if "configuration update complete" in line:
            self.finished(True)

    def poll(self):
        while True:
            data = self.f.read(1000)
            if not data:
                return
            self.dataReceived(data)

class Reconfigurator:
    def run(self, config):

        basedir = config['basedir']
        quiet = config['quiet']
        os.chdir(basedir)
        f = open("twistd.pid", "rt")
        pid = int(f.read().strip())
        if quiet:
            os.kill(pid, signal.SIGHUP)
            return
        # keep reading twistd.log. Display all messages between "loading
        # configuration from ..." and "configuration update complete" or
        # "I will keep using the previous config file instead.", or until
        # 5 seconds have elapsed.
        reactor.callLater(5, self.timeout)
        self.lw = lw = LogWatcher(self.finished)
        if lw.start("twistd.log"):
            # we're watching
            # give the LogWatcher a chance to start reading
            print "sending SIGHUP to process %d" % pid
            reactor.callLater(0.2, os.kill, pid, signal.SIGHUP)
            reactor.run()
        else:
            # we couldn't watch the file.. just SIGHUP it
            os.kill(pid, signal.SIGHUP)
            print "sent SIGHUP to process %d" % pid

    def finished(self, success):
        if success:
            print "Reconfiguration is complete."
        else:
            print "Reconfiguration failed."
        reactor.stop()

    def timeout(self):
        print "Never saw reconfiguration finish."
        reactor.stop()

def reconfig(config):
    r = Reconfigurator()
    r.run(config)


Index: runner.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/scripts/runner.py,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- runner.py	6 Sep 2006 00:41:55 -0000	1.45
+++ runner.py	24 Nov 2006 08:23:27 -0000	1.46
@@ -427,6 +427,15 @@
     def getSynopsis(self):
         return "Usage:    buildbot stop <basedir>"
 
+class ReconfigOptions(MakerBase):
+    optFlags = [
+        ['quiet', 'q', "Don't display log messages about reconfiguration"],
+        ]
+    def getSynopsis(self):
+        return "Usage:    buildbot reconfig <basedir>"
+
+
+
 class RestartOptions(MakerBase):
     def getSynopsis(self):
         return "Usage:    buildbot restart <basedir>"
@@ -669,7 +678,9 @@
         ['restart', None, RestartOptions,
          "Restart a buildmaster or buildslave"],
 
-        ['sighup', None, StopOptions,
+        ['reconfig', None, ReconfigOptions,
+         "SIGHUP a buildmaster to make it re-read the config file"],
+        ['sighup', None, ReconfigOptions,
          "SIGHUP a buildmaster to make it re-read the config file"],
 
         ['sendchange', None, SendChangeOptions,
@@ -731,7 +742,8 @@
     elif command == "restart":
         restart(so)
     elif command == "sighup":
-        stop(so, "HUP")
+        from buildbot.scripts.reconfig import Reconfigurator
+        Reconfigurator().run(so)
     elif command == "sendchange":
         sendchange(so, True)
     elif command == "debugclient":





More information about the Commits mailing list