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

Source Code for Module buildbot.scripts.start

  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 
 18  from buildbot.scripts import base 
 19  from twisted.internet import reactor, protocol 
 20  from twisted.python.runtime import platformType 
 21  from buildbot.scripts.logwatcher import LogWatcher 
 22  from buildbot.scripts.logwatcher import BuildmasterTimeoutError 
 23  from buildbot.scripts.logwatcher import ReconfigError 
 24   
25 -class Follower:
26 - def follow(self, basedir):
27 self.rc = 0 28 print "Following twistd.log until startup finished.." 29 lw = LogWatcher(os.path.join(basedir, "twistd.log")) 30 d = lw.start() 31 d.addCallbacks(self._success, self._failure) 32 reactor.run() 33 return self.rc
34
35 - def _success(self, _):
36 print "The buildmaster appears to have (re)started correctly." 37 self.rc = 0 38 reactor.stop()
39
40 - def _failure(self, why):
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 -def launchNoDaemon(config):
63 os.chdir(config['basedir']) 64 sys.path.insert(0, os.path.abspath(config['basedir'])) 65 66 argv = ["twistd", 67 "--no_save", 68 '--nodaemon', 69 "--logfile=twistd.log", # windows doesn't use the same default 70 "--python=buildbot.tac"] 71 sys.argv = argv 72 73 # this is copied from bin/twistd. twisted-2.0.0 through 2.4.0 use 74 # _twistw.run . Twisted-2.5.0 and later use twistd.run, even for 75 # windows. 76 from twisted.scripts import twistd 77 twistd.run()
78
79 -def launch(config):
80 os.chdir(config['basedir']) 81 sys.path.insert(0, os.path.abspath(config['basedir'])) 82 83 # see if we can launch the application without actually having to 84 # spawn twistd, since spawning processes correctly is a real hassle 85 # on windows. 86 argv = [sys.executable, 87 "-c", 88 # this is copied from bin/twistd. twisted-2.0.0 through 2.4.0 use 89 # _twistw.run . Twisted-2.5.0 and later use twistd.run, even for 90 # windows. 91 "from twisted.scripts import twistd; twistd.run()", 92 "--no_save", 93 "--logfile=twistd.log", # windows doesn't use the same default 94 "--python=buildbot.tac"] 95 96 # ProcessProtocol just ignores all output 97 reactor.spawnProcess(protocol.ProcessProtocol(), sys.executable, argv, env=os.environ)
98
99 -def start(config):
100 if not base.isBuildmasterDir(config['basedir']): 101 print "not a buildmaster directory" 102 return 1 103 104 if config['nodaemon']: 105 launchNoDaemon(config) 106 return 0 107 108 launch(config) 109 110 # We don't have tail on windows 111 if platformType == "win32" or config['quiet']: 112 return 0 113 114 # this is the parent 115 rc = Follower().follow(config['basedir']) 116 return rc
117