1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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