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, _):
32 from twisted.internet import reactor 33 print "The buildmaster appears to have (re)started correctly." 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 from buildbot.scripts.logwatcher import ReconfigError 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(ReconfigError): 48 print """ 49 The buildmaster appears to have encountered an error in the master.cfg config 50 file during startup. Please inspect and fix master.cfg, then restart the 51 buildmaster. 52 """ 53 else: 54 print """ 55 Unable to confirm that the buildmaster started correctly. You may need to 56 stop it, fix the config file, and restart. 57 """ 58 print why 59 self.rc = 1 60 reactor.stop()
61 62
63 -def start(config):
64 os.chdir(config['basedir']) 65 if not os.path.exists("buildbot.tac"): 66 print "This doesn't look like a buildbot base directory:" 67 print "No buildbot.tac file." 68 print "Giving up!" 69 sys.exit(1) 70 if config['quiet']: 71 return launch(config) 72 73 # we probably can't do this os.fork under windows 74 from twisted.python.runtime import platformType 75 if platformType == "win32": 76 return launch(config) 77 78 # fork a child to launch the daemon, while the parent process tails the 79 # logfile 80 if os.fork(): 81 # this is the parent 82 rc = Follower().follow() 83 sys.exit(rc) 84 # this is the child: give the logfile-watching parent a chance to start 85 # watching it before we start the daemon 86 time.sleep(0.2) 87 launch(config)
88
89 -def launch(config):
90 sys.path.insert(0, os.path.abspath(os.getcwd())) 91 92 # see if we can launch the application without actually having to 93 # spawn twistd, since spawning processes correctly is a real hassle 94 # on windows. 95 argv = ["twistd", 96 "--no_save", 97 "--logfile=twistd.log", # windows doesn't use the same default 98 "--python=buildbot.tac"] 99 sys.argv = argv 100 101 # this is copied from bin/twistd. twisted-2.0.0 through 2.4.0 use 102 # _twistw.run . Twisted-2.5.0 and later use twistd.run, even for 103 # windows. 104 from twisted.scripts import twistd 105 twistd.run()
106