def start(config): if not base.isBuildmasterDir(config['basedir']): return 1 py2Warning(config) if config['nodaemon']: launchNoDaemon(config) return 0 launch(config) # We don't have tail on windows if platformType == "win32" or config['quiet']: return 0 # this is the parent timeout = config.get('start_timeout', None) if timeout is not None: try: timeout = float(timeout) except ValueError: print('Start timeout must be a number') return 1 rc = Follower().follow(config['basedir'], timeout=timeout) return rc
def stop(config, signame="TERM", wait=False): basedir = config['basedir'] quiet = config['quiet'] if config['clean']: signame = 'USR1' if not base.isBuildmasterDir(config['basedir']): return 1 pidfile = os.path.join(basedir, 'twistd.pid') try: with open(pidfile, "rt") as f: pid = int(f.read().strip()) except: if not config['quiet']: print "buildmaster not running" return 0 signum = getattr(signal, "SIG" + signame) try: os.kill(pid, signum) except OSError, e: if e.errno != errno.ESRCH: raise else: if not config['quiet']: print "buildmaster not running" try: os.unlink(pidfile) except: pass return 0
def test_isBuildmasterDir_no_Application(self): # Loading of pre-0.9.0 buildbot.tac file should fail. with open(os.path.join('test', 'buildbot.tac'), 'w') as f: f.write("foo\nx = Application('buildslave')\nbar") self.assertFalse(base.isBuildmasterDir(os.path.abspath('test'))) self.assertInStdout('unexpected content') self.assertInStdout('invalid buildmaster directory')
def checkBasedir(config): if not config['quiet']: print "checking basedir" if not base.isBuildmasterDir(config['basedir']): return False if runtime.platformType != 'win32': # no pids on win32 if not config['quiet']: print "checking for running master" pidfile = os.path.join(config['basedir'], 'twistd.pid') if os.path.exists(pidfile): print "'%s' exists - is this master still running?" % (pidfile, ) return False tac = base.getConfigFromTac(config['basedir']) if tac: if isinstance(tac.get('rotateLength', 0), str): print "WARNING: rotateLength is a string, it should be a number" return False if isinstance(tac.get('maxRotatedFiles', 0), str): print "WARNING: maxRotatedFiles is a string, it should be a number" return False return True
def checkBasedir(config): if not config['quiet']: print "checking basedir" if not base.isBuildmasterDir(config['basedir']): return False if runtime.platformType != 'win32': # no pids on win32 if not config['quiet']: print "checking for running master" pidfile = os.path.join(config['basedir'], 'twistd.pid') if os.path.exists(pidfile): print "'%s' exists - is this master still running?" % (pidfile,) return False tac = base.getConfigFromTac(config['basedir']) if tac: if isinstance(tac.get('rotateLength', 0), str): print "ERROR: rotateLength is a string, it should be a number" print "ERROR: Please, edit your buildbot.tac file and run again" print "ERROR: See http://trac.buildbot.net/ticket/2588 for more details" return False if isinstance(tac.get('maxRotatedFiles', 0), str): print "ERROR: maxRotatedFiles is a string, it should be a number" print "ERROR: Please, edit your buildbot.tac file and run again" print "ERROR: See http://trac.buildbot.net/ticket/2588 for more details" return False return True
def checkBasedir(config): if not config['quiet']: print "checking basedir" if not base.isBuildmasterDir(config['basedir']): return False if runtime.platformType != 'win32': # no pids on win32 if not config['quiet']: print "checking for running master" pidfile = os.path.join(config['basedir'], 'twistd.pid') if os.path.exists(pidfile): print "'%s' exists - is this master still running?" % (pidfile,) return False tac = base.getConfigFromTac(config['basedir']) if tac: if isinstance(tac.get('rotateLength', 0), str): print "WARNING: rotateLength is a string, it should be a number" return False if isinstance(tac.get('maxRotatedFiles', 0), str): print "WARNING: maxRotatedFiles is a string, it should be a number" return False return True
def stop(config, signame="TERM", wait=None): basedir = config['basedir'] quiet = config['quiet'] if wait is None: wait = not config['no-wait'] if config['clean']: signame = 'USR1' if not base.isBuildmasterDir(config['basedir']): return 1 pidfile = os.path.join(basedir, 'twistd.pid') try: with open(pidfile, "rt") as f: pid = int(f.read().strip()) except Exception: if not config['quiet']: print("buildmaster not running") return 0 signum = getattr(signal, "SIG" + signame) try: os.kill(pid, signum) except OSError as e: if e.errno != errno.ESRCH: raise else: if not config['quiet']: print("buildmaster not running") try: os.unlink(pidfile) except OSError: pass return 0 if not wait: if not quiet: print("sent SIG%s to process" % signame) return 0 time.sleep(0.1) # poll once per second until twistd.pid goes away, up to 10 seconds, # unless we're doing a clean stop, in which case wait forever count = 0 while count < 10 or config['clean']: try: os.kill(pid, 0) except OSError: if not quiet: print("buildbot process %d is dead" % pid) return 0 time.sleep(1) count += 1 if not quiet: print("never saw process go away") return 1
def restart(config): basedir = config['basedir'] quiet = config['quiet'] if not base.isBuildmasterDir(basedir): return 1 if stop.stop(config, wait=True) != 0: return 1 if not quiet: print("now restarting buildbot process..") return start.start(config)
def restart(config): basedir = config["basedir"] quiet = config["quiet"] if not base.isBuildmasterDir(basedir): print "not a buildmaster directory" return 1 if stop.stop(config, wait=True) != 0: return 1 if not quiet: print "now restarting buildbot process.." return start.start(config)
def checkBasedir(config): if not config['quiet']: print "checking basedir" if not base.isBuildmasterDir(config['basedir']): return False if runtime.platformType != 'win32': # no pids on win32 if not config['quiet']: print "checking for running master" # isBuildBotRunning will clean up the .pid file if the build isn't running if base.isBuildBotRunning(config['basedir'], config['quiet']): return False return True
def checkBasedir(config): if not config['quiet']: print "checking basedir" if not base.isBuildmasterDir(config['basedir']): return False if runtime.platformType != 'win32': # no pids on win32 if not config['quiet']: print "checking for running master" pidfile = os.path.join(config['basedir'], 'twistd.pid') if os.path.exists(pidfile): print "'%s' exists - is this master still running?" % (pidfile, ) return False return True
def checkBasedir(config): if not config['quiet']: print "checking basedir" if not base.isBuildmasterDir(config['basedir']): return False if runtime.platformType != 'win32': # no pids on win32 if not config['quiet']: print "checking for running master" pidfile = os.path.join(config['basedir'], 'twistd.pid') if os.path.exists(pidfile): print "'%s' exists - is this master still running?" % (pidfile,) return False return True
def start(config): if not base.isBuildmasterDir(config['basedir']): return 1 if config['nodaemon']: launchNoDaemon(config) return 0 launch(config) # We don't have tail on windows if platformType == "win32" or config['quiet']: return 0 # this is the parent rc = Follower().follow(config['basedir']) return rc
def start(config): if not base.isBuildmasterDir(config['basedir']): print "not a buildmaster directory" return 1 if config['quiet']: launch(config) return 0 # we probably can't do this os.fork under windows if platformType == "win32": launch(config) return 0 # fork a child to launch the daemon, while the parent process tails the # logfile if os.fork(): # this is the parent rc = Follower().follow(config['basedir']) return rc # this is the child: give the logfile-watching parent a chance to start # watching it before we start the daemon time.sleep(0.2) launch(config)
def test_isBuildmasterDir_no_Application(self): with open(os.path.join('test', 'buildbot.tac'), 'w') as f: f.write("foo\nx = Application('buildworker')\nbar") self.assertFalse(base.isBuildmasterDir(os.path.abspath('test'))) self.assertInStdout('unexpected content') self.assertInStdout('invalid buildmaster directory')
def test_isBuildmasterDir_no_file(self): self.assertFalse(base.isBuildmasterDir(os.path.abspath('test'))) self.assertInStdout('error reading') self.assertInStdout('invalid buildmaster directory')
def test_isBuildmasterDir_matches(self): with open(os.path.join('test', 'buildbot.tac'), 'w') as f: f.write("foo\nx = Application('buildmaster')\nbar") self.assertTrue(base.isBuildmasterDir(os.path.abspath('test'))) self.assertWasQuiet()
def test_isBuildmasterDir_no_file(self): self.assertFalse(base.isBuildmasterDir(os.path.abspath('test'))) self.assertInStdout('no buildbot.tac')
def test_isBuildmasterDir_no_Application(self): with open(os.path.join("test", "buildbot.tac"), "w") as f: f.write("foo\nx = Application('buildslave')\nbar") self.assertFalse(base.isBuildmasterDir(os.path.abspath("test"))) self.assertInStdout("unexpected content") self.assertInStdout("invalid buildmaster directory")
def test_isBuildmasterDir_no_file(self): self.assertFalse(base.isBuildmasterDir(os.path.abspath("test"))) self.assertInStdout("error reading") self.assertInStdout("invalid buildmaster directory")