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..9c77e05cae43e0c255ce8263c6e917ca8d3177e9 |
--- /dev/null |
+++ b/scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py |
@@ -0,0 +1,64 @@ |
+#!/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', |
+ 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) |
+ if pid == 0 and retcode == 0: |
+ break |
+ |
+ if pid != 0 or retcode != 0: |
+ os.kill(killed_pid, os.SIGKILL) |
+ |
+ |
+ |
Yoshisato Yanagisawa
2016/08/16 04:16:24
nit one extra space?
tikuta
2016/08/16 05:09:55
Done.
|
+if '__main__' == __name__: |
+ sys.exit(main()) |