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

Source Code for Module buildslave.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 buildslave.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 buildslave.scripts.logwatcher import BuildmasterTimeoutError, \ 40 ReconfigError, BuildslaveTimeoutError, BuildSlaveDetectedError 41 if why.check(BuildmasterTimeoutError): 42 print """ 43 The buildslave 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 buildslave, 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 buildslave, or the buildslave 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 buildslave 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 buildslave. 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 buildslave 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 config['quiet']: 83 return launch(config) 84 85 # we probably can't do this os.fork under windows 86 from twisted.python.runtime import platformType 87 if platformType == "win32": 88 return launch(config) 89 90 # fork a child to launch the daemon, while the parent process tails the 91 # logfile 92 if os.fork(): 93 # this is the parent 94 rc = Follower().follow() 95 sys.exit(rc) 96 # this is the child: give the logfile-watching parent a chance to start 97 # watching it before we start the daemon 98 time.sleep(0.2) 99 launch(config)
100
101 -def launch(config):
102 sys.path.insert(0, os.path.abspath(os.getcwd())) 103 104 # see if we can launch the application without actually having to 105 # spawn twistd, since spawning processes correctly is a real hassle 106 # on windows. 107 from twisted.python.runtime import platformType 108 argv = ["twistd", 109 "--no_save", 110 "--logfile=twistd.log", # windows doesn't use the same default 111 "--python=buildbot.tac"] 112 sys.argv = argv 113 114 # this is copied from bin/twistd. twisted-2.0.0 through 2.4.0 use 115 # _twistw.run . Twisted-2.5.0 and later use twistd.run, even for 116 # windows. 117 from twisted import __version__ 118 major, minor, ignored = __version__.split(".", 2) 119 major = int(major) 120 minor = int(minor) 121 if (platformType == "win32" and (major == 2 and minor < 5)): 122 from twisted.scripts import _twistw 123 run = _twistw.run 124 else: 125 from twisted.scripts import twistd 126 run = twistd.run 127 run()
128