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

Source Code for Module buildbot.scripts.startup

  1   
  2  import os, sys, time 
  3   
4 -class Follower:
5 - def follow(self):
6 from twisted.internet import reactor 7 from buildbot.scripts.logwatcher import LogWatcher 8 self.rc = 0 9 print "Following twistd.log until startup finished.." 10 lw = LogWatcher("twistd.log") 11 d = lw.start() 12 d.addCallbacks(self._success, self._failure) 13 reactor.run() 14 return self.rc
15
16 - def _success(self, processtype):
17 from twisted.internet import reactor 18 print "The %s appears to have (re)started correctly." % processtype 19 self.rc = 0 20 reactor.stop()
21
22 - def _failure(self, why):
23 from twisted.internet import reactor 24 from buildbot.scripts.logwatcher import BuildmasterTimeoutError, \ 25 ReconfigError, BuildslaveTimeoutError, BuildSlaveDetectedError 26 if why.check(BuildmasterTimeoutError): 27 print """ 28 The buildmaster took more than 10 seconds to start, so we were unable to 29 confirm that it started correctly. Please 'tail twistd.log' and look for a 30 line that says 'configuration update complete' to verify correct startup. 31 """ 32 elif why.check(BuildslaveTimeoutError): 33 print """ 34 The buildslave took more than 10 seconds to start and/or connect to the 35 buildmaster, so we were unable to confirm that it started and connected 36 correctly. Please 'tail twistd.log' and look for a line that says 'message 37 from master: attached' to verify correct startup. If you see a bunch of 38 messages like 'will retry in 6 seconds', your buildslave might not have the 39 correct hostname or portnumber for the buildmaster, or the buildmaster might 40 not be running. If you see messages like 41 'Failure: twisted.cred.error.UnauthorizedLogin' 42 then your buildslave might be using the wrong botname or password. Please 43 correct these problems and then restart the buildslave. 44 """ 45 elif why.check(ReconfigError): 46 print """ 47 The buildmaster appears to have encountered an error in the master.cfg config 48 file during startup. It is probably running with an empty configuration right 49 now. Please inspect and fix master.cfg, then restart the buildmaster. 50 """ 51 elif why.check(BuildSlaveDetectedError): 52 print """ 53 Buildslave is starting up, not following logfile. 54 """ 55 else: 56 print """ 57 Unable to confirm that the buildmaster started correctly. You may need to 58 stop it, fix the config file, and restart. 59 """ 60 print why 61 self.rc = 1 62 reactor.stop()
63 64
65 -def start(config):
66 os.chdir(config['basedir']) 67 if (not os.path.exists("buildbot.tac") and 68 not os.path.exists("Makefile.buildbot")): 69 print "This doesn't look like a buildbot base directory:" 70 print "No buildbot.tac or Makefile.buildbot file." 71 print "Giving up!" 72 sys.exit(1) 73 if config['quiet']: 74 return launch(config) 75 76 # we probably can't do this os.fork under windows 77 from twisted.python.runtime import platformType 78 if platformType == "win32": 79 return launch(config) 80 81 # fork a child to launch the daemon, while the parent process tails the 82 # logfile 83 if os.fork(): 84 # this is the parent 85 rc = Follower().follow() 86 sys.exit(rc) 87 # this is the child: give the logfile-watching parent a chance to start 88 # watching it before we start the daemon 89 time.sleep(0.2) 90 launch(config)
91
92 -def launch(config):
93 sys.path.insert(0, os.path.abspath(os.getcwd())) 94 if os.path.exists("/usr/bin/make") and os.path.exists("Makefile.buildbot"): 95 # Preferring the Makefile lets slave admins do useful things like set 96 # up environment variables for the buildslave. 97 cmd = "make -f Makefile.buildbot start" 98 if not config['quiet']: 99 print cmd 100 os.system(cmd) 101 else: 102 # see if we can launch the application without actually having to 103 # spawn twistd, since spawning processes correctly is a real hassle 104 # on windows. 105 from twisted.python.runtime import platformType 106 argv = ["twistd", 107 "--no_save", 108 "--logfile=twistd.log", # windows doesn't use the same default 109 "--python=buildbot.tac"] 110 sys.argv = argv 111 112 # this is copied from bin/twistd. twisted-2.0.0 through 2.4.0 use 113 # _twistw.run . Twisted-2.5.0 and later use twistd.run, even for 114 # windows. 115 from twisted import __version__ 116 major, minor, ignored = __version__.split(".", 2) 117 major = int(major) 118 minor = int(minor) 119 if (platformType == "win32" and (major == 2 and minor < 5)): 120 from twisted.scripts import _twistw 121 run = _twistw.run 122 else: 123 from twisted.scripts import twistd 124 run = twistd.run 125 run()
126