OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import os | |
8 import signal | |
9 import subprocess | |
10 import sys | |
11 import time | |
12 | |
13 from slave import goma_utils | |
14 | |
15 | |
16 def start_cloudtail(args, f): | |
17 """Write process id of started cloudtail to file object f""" | |
18 | |
19 proc = subprocess.Popen([args.cloudtail_path, | |
20 'tail', | |
21 '--log-id', 'goma_compiler_proxy' | |
22 '--path', | |
23 goma_utils.GetLatestGomaCompilerProxyInfo()]) | |
24 | |
25 f.write(str(proc.pid)) | |
26 | |
27 | |
28 def main(): | |
29 parser = argparse.ArgumentParser( | |
30 description='cloudtail utility for goma recipe module.') | |
31 | |
32 parser.add_argument('--cloudtail-path', | |
33 help='path of cloudtail binary') | |
34 parser.add_argument('--start-cloudtail', action='store_true', | |
35 help='start cloudtail if this option is enabled') | |
36 parser.add_argument('--killed-pid', type=int, | |
Paweł Hajdan Jr.
2016/08/17 06:27:01
This can easily get messy.
Could you refactor thi
tikuta
2016/08/17 07:51:32
Done.
| |
37 help=('pid that is killed.' | |
38 ' Do not set this option and' | |
39 ' --start-cloudtail at the same time')) | |
40 | |
41 args = parser.parse_args() | |
42 | |
43 if args.start_cloudtail: | |
44 # Do not set killed_pid and start_cloudtail at the same time | |
45 assert args.killed_pid is None | |
46 start_cloudtail(args, sys.stdout) | |
47 | |
48 if args.killed_pid is not None: | |
49 killed_pid = args.killed_pid | |
50 # only send SIGKILL signal, let init process do wait for killed_pid | |
51 os.kill(killed_pid, os.SIGKILL) | |
52 | |
53 | |
54 if '__main__' == __name__: | |
55 sys.exit(main()) | |
OLD | NEW |