15 16# the create/start/stop commands should all be run as the same user, 17# preferably a separate 'buildbot' account. 18 19# Note that the terms 'options' and 'config' are used intechangeably here - in 20# fact, they are intercanged several times. Caveat legator. 21

171importsignal172basedir=config['basedir']173quiet=config['quiet']174175ifnotisBuildslaveDir(config['basedir']):176print"not a buildslave directory"177sys.exit(1)178179os.chdir(basedir)180try:181f=open("twistd.pid","rt")182except:183ifreturnFalseOnNotRunning:184returnFalse185ifnotquiet:print"buildslave not running."186sys.exit(0)187pid=int(f.read().strip())188signum=getattr(signal,"SIG"+signame)189timer=0190try:191os.kill(pid,signum)192exceptOSError,e:193ife.errno!=3:194raise195196ifnotwait:197ifnotquiet:198print"sent SIG%s to process"%signame199return200time.sleep(0.1)201whiletimer<10:202# poll once per second until twistd.pid goes away, up to 10 seconds203try:204os.kill(pid,0)205exceptOSError:206ifnotquiet:207print"buildslave process %d is dead"%pid208return209timer+=1210time.sleep(1)211ifnotquiet:212print"never saw process go away"

232optFlags=[233['help','h',"Display this message"],234["quiet","q","Do not emit the commands being run"],235]236237longdesc="""238 Operates upon the specified <basedir> (or the current directory, if not239 specified).240 """241242opt_h=usage.Options.opt_help243

245iflen(args)>0:246self['basedir']=args[0]247else:248# Use the current directory if no basedir was specified.249self['basedir']=os.getcwd()250iflen(args)>1:251raiseusage.UsageError("I wasn't expecting so many arguments")

304optFlags=[305["force","f","Re-use an existing directory"],306["relocatable","r",307"Create a relocatable buildbot.tac"],308["no-logrotate","n",309"Do not permit buildmaster rotate logs by itself"]310]311optParameters=[312["keepalive","k",600,313"Interval at which keepalives should be sent (in seconds)"],314["usepty",None,0,315"(1 or 0) child processes should be run in a pty (default 0)"],316["umask",None,"None",317"controls permissions of generated files. Use --umask=022 to be world-readable"],318["maxdelay",None,300,319"Maximum time between connection attempts"],320["log-size","s","10000000",321"size at which to rotate twisted log files"],322["log-count","l","10",323"limit the number of kept old twisted log files (None for unlimited)"],324]325326longdesc="""327 This command creates a buildslave working directory and buildbot.tac328 file. The bot will use the <name> and <passwd> arguments to authenticate329 itself when connecting to the master. All commands are run in a330 build-specific subdirectory of <basedir>. <master> is a string of the331 form 'hostname[:port]', and specifies where the buildmaster can be reached.332 port defaults to 9989333334 The appropriate values for <name>, <passwd>, and <master> should be335 provided to you by the buildmaster administrator. You must choose <basedir>336 yourself.337 """338

354MakerBase.postOptions(self)355self['usepty']=int(self['usepty'])356self['keepalive']=int(self['keepalive'])357self['maxdelay']=int(self['maxdelay'])358ifnotre.match('^\d+$',self['log-size']):359raiseusage.UsageError("log-size parameter needs to be an int")360ifnotre.match('^\d+$',self['log-count'])and \ 361self['log-count']!='None':362raiseusage.UsageError("log-count parameter needs to be an int "+363" or None")

366synopsis="Usage: buildslave <command> [command options]"367368subCommands=[369# the following are all admin commands370['create-slave',None,SlaveOptions,371"Create and populate a directory for a new buildslave"],372['upgrade-slave',None,UpgradeSlaveOptions,373"Upgrade an existing buildslave directory for the current version"],374['start',None,StartOptions,"Start a buildslave"],375['stop',None,StopOptions,"Stop a buildslave"],376['restart',None,RestartOptions,377"Restart a buildslave"],378]379