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..9bb4a439680fce118074d97c20093d2b2c73bc89 |
| --- /dev/null |
| +++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
| @@ -0,0 +1,55 @@ |
| +#!/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', 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.
|
| + 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 = args.killed_pid |
| + # only send SIGKILL signal, let init process do wait for killed_pid |
| + os.kill(killed_pid, os.SIGKILL) |
| + |
| + |
| +if '__main__' == __name__: |
| + sys.exit(main()) |