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

Source Code for Module buildbot.scripts.startup

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