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

Source Code for Module buildbot.scripts.stop

 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  from __future__ import with_statement 
17   
18  import time 
19  import os 
20  import errno 
21  import signal 
22  from buildbot.scripts import base 
23   
24 -def stop(config, signame="TERM", wait=False):
25 basedir = config['basedir'] 26 quiet = config['quiet'] 27 28 if not base.isBuildmasterDir(config['basedir']): 29 print "not a buildmaster directory" 30 return 1 31 32 pidfile = os.path.join(basedir, 'twistd.pid') 33 try: 34 with open(pidfile, "rt") as f: 35 pid = int(f.read().strip()) 36 except: 37 if not config['quiet']: 38 print "buildmaster not running" 39 return 0 40 41 signum = getattr(signal, "SIG"+signame) 42 try: 43 os.kill(pid, signum) 44 except OSError, e: 45 if e.errno != errno.ESRCH: 46 raise 47 else: 48 if not config['quiet']: 49 print "buildmaster not running" 50 try: 51 os.unlink(pidfile) 52 except: 53 pass 54 return 0 55 56 if not wait: 57 if not quiet: 58 print "sent SIG%s to process" % signame 59 return 0 60 61 time.sleep(0.1) 62 for _ in range(10): 63 # poll once per second until twistd.pid goes away, up to 10 seconds 64 try: 65 os.kill(pid, 0) 66 except OSError: 67 if not quiet: 68 print "buildbot process %d is dead" % pid 69 return 0 70 time.sleep(1) 71 if not quiet: 72 print "never saw process go away" 73 return 1
74