Package buildbot :: Package scripts :: Module reconfig
[frames] | no frames]

Source Code for Module buildbot.scripts.reconfig

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16   
17  import os 
18  import signal 
19  import platform 
20  import sys 
21  from twisted.internet import reactor 
22   
23  from buildbot.scripts.logwatcher import LogWatcher, BuildmasterTimeoutError, \ 
24       ReconfigError 
25   
26 -class Reconfigurator:
27 28 rc = 0 29
30 - def run(self, config):
31 # Returns "Microsoft" for Vista and "Windows" for other versions 32 if platform.system() in ("Windows", "Microsoft"): 33 print "Reconfig (through SIGHUP) is not supported on Windows." 34 print "The 'buildbot debugclient' tool can trigger a reconfig" 35 print "remotely, but requires Gtk+ libraries to run." 36 return 37 38 basedir = config['basedir'] 39 quiet = config['quiet'] 40 os.chdir(basedir) 41 f = open("twistd.pid", "rt") 42 self.pid = int(f.read().strip()) 43 if quiet: 44 os.kill(self.pid, signal.SIGHUP) 45 return 46 47 # keep reading twistd.log. Display all messages between "loading 48 # configuration from ..." and "configuration update complete" or 49 # "I will keep using the previous config file instead.", or until 50 # 10 seconds have elapsed. 51 52 self.sent_signal = False 53 lw = LogWatcher("twistd.log") 54 d = lw.start() 55 d.addCallbacks(self.success, self.failure) 56 reactor.callLater(0.2, self.sighup) 57 reactor.run() 58 sys.exit(self.rc)
59
60 - def sighup(self):
61 if self.sent_signal: 62 return 63 print "sending SIGHUP to process %d" % self.pid 64 self.sent_signal = True 65 os.kill(self.pid, signal.SIGHUP)
66
67 - def success(self, res):
68 print """ 69 Reconfiguration appears to have completed successfully. 70 """ 71 reactor.stop()
72
73 - def failure(self, why):
74 self.rc = 1 75 if why.check(BuildmasterTimeoutError): 76 print "Never saw reconfiguration finish." 77 elif why.check(ReconfigError): 78 print """ 79 Reconfiguration failed. Please inspect the master.cfg file for errors, 80 correct them, then try 'buildbot reconfig' again. 81 """ 82 elif why.check(IOError): 83 # we were probably unable to open the file in the first place 84 self.sighup() 85 else: 86 print "Error while following twistd.log: %s" % why 87 reactor.stop()
88