Chromium Code Reviews| 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 | |
| 12 from slave import goma_utils | |
| 13 | |
| 14 | |
| 15 def start_cloudtail(args, f): | |
| 16 """Write process id of started cloudtail to file object f""" | |
| 17 | |
| 18 proc = subprocess.Popen([args.cloudtail_path, | |
| 19 'tail', | |
| 20 '--log-id', 'goma_compiler_proxy' | |
| 21 '--path', | |
| 22 goma_utils.GetLatestGomaCompilerProxyInfo()]) | |
| 23 | |
| 24 f.write(str(proc.pid)) | |
| 25 | |
| 26 | |
| 27 def main(): | |
| 28 parser = argparse.ArgumentParser( | |
| 29 description='cloudtail utility for goma recipe module.') | |
| 30 | |
| 31 parser.add_argument('--cloudtail-path', | |
| 32 help='path of cloudtail binary') | |
| 33 parser.add_argument('--start-cloudtail', action='store_true', | |
| 34 help='start cloudtail if this option is enabled') | |
| 35 parser.add_argument('--killed-pid', | |
| 36 help=('pid that is killed.' | |
| 37 ' Do not set this option and' | |
| 38 ' --start-cloudtail at the same time')) | |
| 39 | |
| 40 args = parser.parse_args() | |
| 41 | |
| 42 if args.start_cloudtail: | |
| 43 # Do not set killed_pid and start_cloudtail at the same time | |
| 44 assert args.killed_pid is None | |
| 45 start_cloudtail(args, sys.stdout) | |
| 46 | |
| 47 if args.killed_pid is not None: | |
| 48 killed_pid = int(args.killed_pid) | |
| 49 os.kill(killed_pid, signal.SIGTERM) | |
| 50 pid, retcode = os.waitpid(killed_pid, os.WNOHANG) | |
|
Yoshisato Yanagisawa
2016/08/16 03:45:23
Don't you need to retry for a while?
tikuta
2016/08/16 03:59:31
Done.
| |
| 51 if pid == 0 and retcode == 0: | |
| 52 os.kill(killed_pid, os.SIGKILL) | |
| 53 | |
| 54 | |
| 55 if '__main__' == __name__: | |
| 56 sys.exit(main()) | |
| OLD | NEW |