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..5a9e0dbe9defb30a27fe371fc17a2e21e8f387be |
| --- /dev/null |
| +++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| @@ -0,0 +1,56 @@ |
| +#!/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 |
| + |
| +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', |
| + 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) |
| + 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.
|
| + if pid == 0 and retcode == 0: |
| + os.kill(killed_pid, os.SIGKILL) |
| + |
| + |
| +if '__main__' == __name__: |
| + sys.exit(main()) |