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', |
| 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 = int(args.killed_pid) |
| 50 os.kill(killed_pid, signal.SIGTERM) |
| 51 |
| 52 for _ in range(3): |
| 53 time.sleep(1) |
| 54 pid, retcode = os.waitpid(killed_pid, os.WNOHANG) |
| 55 if pid == 0 and retcode == 0: |
| 56 break |
| 57 |
| 58 if pid != 0 or retcode != 0: |
| 59 os.kill(killed_pid, os.SIGKILL) |
| 60 |
| 61 |
| 62 if '__main__' == __name__: |
| 63 sys.exit(main()) |
OLD | NEW |