Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: scripts/slave/recipe_modules/goma/resources/cloudtail_utils.py

Issue 2386073002: Wait cloudtail termination in goma module (Closed)
Patch Set: add SIGKILL Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import errno 7 import errno
8 import os 8 import os
9 import signal 9 import signal
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import time
12 13
13 from slave import goma_utils 14 from slave import goma_utils
14 15
15 16
16 def start_cloudtail(args): 17 def start_cloudtail(args):
17 """Write process id of started cloudtail to file object f""" 18 """Write process id of started cloudtail to file object f"""
18 19
19 proc = subprocess.Popen([args.cloudtail_path, 20 proc = subprocess.Popen([args.cloudtail_path,
20 'tail', 21 'tail',
21 '--log-id', 'goma_compiler_proxy', 22 '--log-id', 'goma_compiler_proxy',
22 '--path', 23 '--path',
23 goma_utils.GetLatestGomaCompilerProxyInfo()]) 24 goma_utils.GetLatestGomaCompilerProxyInfo()])
24 with open(args.pid_file, 'w') as f: 25 with open(args.pid_file, 'w') as f:
25 f.write(str(proc.pid)) 26 f.write(str(proc.pid))
26 27
28 def is_running_posix(pid):
29 try:
ukai 2016/10/04 04:58:44 docstring?
tikuta 2016/10/04 05:18:08 Done.
30 os.kill(pid, signal.SIGINT)
ukai 2016/10/04 04:58:44 os.kill(pid, 0) ?
tikuta 2016/10/04 05:18:08 Done.
31 except OSError as e:
32 if e.errno == errno.ESRCH or e.errno == errno.EPERM:
33 return False
34 os.kill(pid, signal.SIGKILL)
35 raise e
36 return True
37
38 def wait_termination(pid):
ukai 2016/10/04 04:58:44 docstring?
tikuta 2016/10/04 05:18:08 Done.
39 os.kill(pid, signal.SIGINT)
ukai 2016/10/04 04:58:44 no exception is expected here?
tikuta 2016/10/04 05:18:08 If exception occurs, I kill cloudtail and raise sa
40
41 if os.name == 'nt':
42 os.waitpid(pid, 0)
43 else:
44 for i in range(10):
45 if not is_running_posix(pid):
46 break
47 time.sleep(1)
48
49 if is_running_posix(pid):
50 os.kill(pid, signal.SIGKILL)
51
27 def main(): 52 def main():
28 parser = argparse.ArgumentParser( 53 parser = argparse.ArgumentParser(
29 description='cloudtail utility for goma recipe module.') 54 description='cloudtail utility for goma recipe module.')
30 55
31 subparsers = parser.add_subparsers(help='commands for cloudtail') 56 subparsers = parser.add_subparsers(help='commands for cloudtail')
32 57
33 parser_start = subparsers.add_parser('start', 58 parser_start = subparsers.add_parser('start',
34 help='subcommand to start cloudtail') 59 help='subcommand to start cloudtail')
35 parser_start.set_defaults(command='start') 60 parser_start.set_defaults(command='start')
36 parser_start.add_argument('--cloudtail-path', required=True, 61 parser_start.add_argument('--cloudtail-path', required=True,
37 help='path of cloudtail binary') 62 help='path of cloudtail binary')
38 parser_start.add_argument('--pid-file', required=True, 63 parser_start.add_argument('--pid-file', required=True,
39 help='file written pid') 64 help='file written pid')
40 65
41 parser_stop = subparsers.add_parser('stop', 66 parser_stop = subparsers.add_parser('stop',
42 help='subcommand to stop cloudtail') 67 help='subcommand to stop cloudtail')
43 parser_stop.set_defaults(command='stop') 68 parser_stop.set_defaults(command='stop')
44 parser_stop.add_argument('--killed-pid-file', required=True, 69 parser_stop.add_argument('--killed-pid-file', required=True,
45 help='file written the pid to be killed.') 70 help='file written the pid to be killed.')
46 71
47 args = parser.parse_args() 72 args = parser.parse_args()
48 73
49 if args.command == 'start': 74 if args.command == 'start':
50 start_cloudtail(args) 75 start_cloudtail(args)
51 elif args.command == 'stop': 76 elif args.command == 'stop':
52 with open(args.killed_pid_file) as f: 77 with open(args.killed_pid_file) as f:
53 # cloudtail flushes log and terminates 78 # cloudtail flushes log and terminates
54 # within 5 seconds when it recieves SIGINT. 79 # within 5 seconds when it recieves SIGINT.
55 os.kill(int(f.read()), signal.SIGINT) 80 wait_termination(int(f.read()))
56 81
57 if '__main__' == __name__: 82 if '__main__' == __name__:
58 sys.exit(main()) 83 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698