Skip to content

Commit

Permalink
refactor reconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Apr 9, 2012
1 parent ed22dab commit f8bb0cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions master/buildbot/scripts/reconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,25 @@
import os
import signal
import platform
import sys
from twisted.internet import reactor

from buildbot.scripts.logwatcher import LogWatcher, BuildmasterTimeoutError, \
ReconfigError
from buildbot.util import in_reactor

class Reconfigurator:

rc = 0

def run(self, config):
def run(self, basedir, quiet):
# Returns "Microsoft" for Vista and "Windows" for other versions
if platform.system() in ("Windows", "Microsoft"):
print "Reconfig (through SIGHUP) is not supported on Windows."
print "The 'buildbot debugclient' tool can trigger a reconfig"
print "remotely, but requires Gtk+ libraries to run."
return

basedir = config['basedir']
quiet = config['quiet']
os.chdir(basedir)
with open("twistd.pid", "rt") as f:
with open(os.path.join(basedir, "twistd.pid"), "rt") as f:
self.pid = int(f.read().strip())
if quiet:
os.kill(self.pid, signal.SIGHUP)
Expand All @@ -52,12 +49,13 @@ def run(self, config):
# 10 seconds have elapsed.

self.sent_signal = False
lw = LogWatcher("twistd.log")
reactor.callLater(0.2, self.sighup)

lw = LogWatcher(os.path.join("twistd.log"))
d = lw.start()
d.addCallbacks(self.success, self.failure)
reactor.callLater(0.2, self.sighup)
reactor.run()
sys.exit(self.rc)
d.addBoth(lambda _ : self.rc)
return d

def sighup(self):
if self.sent_signal:
Expand All @@ -70,7 +68,6 @@ def success(self, res):
print """
Reconfiguration appears to have completed successfully.
"""
reactor.stop()

def failure(self, why):
self.rc = 1
Expand All @@ -86,5 +83,10 @@ def failure(self, why):
self.sighup()
else:
print "Error while following twistd.log: %s" % why
reactor.stop()

@in_reactor
def reconfig(config):
basedir = config['basedir']
quiet = config['quiet']
r = Reconfigurator()
return r.run(basedir, quiet)
4 changes: 2 additions & 2 deletions master/buildbot/scripts/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,8 @@ def run():
from buildbot.scripts import restart
sys.exit(restart.restart(so))
elif command == "reconfig" or command == "sighup":
from buildbot.scripts.reconfig import Reconfigurator
Reconfigurator().run(so)
from buildbot.scripts.reconfig import reconfig
sys.exit(reconfig(so))
elif command == "sendchange":
if not sendchange(so, True):
sys.exit(1)
Expand Down

0 comments on commit f8bb0cd

Please sign in to comment.