Chromium Code Reviews| Index: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| diff --git a/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a90388767f97540d5601eb37396e0d24d10d3dad |
| --- /dev/null |
| +++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| @@ -0,0 +1,63 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import argparse |
| +import os |
| +import signal |
| +import subprocess |
| +import sys |
| +import time |
| + |
| +from slave import goma_utils |
| + |
| + |
| +def start_cloudtail(args, f): |
| + """Write process id of started cloudtail to file object f""" |
| + |
| + proc = subprocess.Popen([args.cloudtail_path, |
| + 'tail', |
| + '--log-id', 'goma_compiler_proxy' |
| + '--path', |
| + goma_utils.GetLatestGomaCompilerProxyInfo()]) |
| + |
| + f.write(str(proc.pid)) |
| + |
| + |
| +def main(): |
| + parser = argparse.ArgumentParser( |
| + description='cloudtail utility for goma recipe module.') |
| + |
| + parser.add_argument('--cloudtail-path', |
| + help='path of cloudtail binary') |
| + parser.add_argument('--start-cloudtail', action='store_true', |
| + help='start cloudtail if this option is enabled') |
| + parser.add_argument('--killed-pid', |
|
ukai
2016/08/17 01:13:15
type=int
?
tikuta
2016/08/17 02:29:56
Done.
|
| + help=('pid that is killed.' |
| + ' Do not set this option and' |
| + ' --start-cloudtail at the same time')) |
| + |
| + args = parser.parse_args() |
| + |
| + if args.start_cloudtail: |
| + # Do not set killed_pid and start_cloudtail at the same time |
| + assert args.killed_pid is None |
| + start_cloudtail(args, sys.stdout) |
| + |
| + if args.killed_pid is not None: |
| + killed_pid = int(args.killed_pid) |
| + os.kill(killed_pid, signal.SIGTERM) |
| + |
| + for _ in range(3): |
| + time.sleep(1) |
| + pid, retcode = os.waitpid(killed_pid, os.WNOHANG) |
|
ukai
2016/08/17 01:13:15
check OSError?
ukai
2016/08/17 01:13:15
os.waitpid won't work with the process id that is
tikuta
2016/08/17 02:29:56
I decided to send kill signal only for killed_pid.
|
| + if pid == 0 and retcode == 0: |
|
ukai
2016/08/17 01:13:15
if pid == 0 and retcode ==0 is still running, so s
|
| + break |
| + |
| + if pid != 0 or retcode != 0: |
|
ukai
2016/08/17 01:13:15
if pid == 0 and retcode == 0?
|
| + os.kill(killed_pid, os.SIGKILL) |
| + |
| + |
| +if '__main__' == __name__: |
| + sys.exit(main()) |