Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 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 signal | 6 import signal |
| 7 import socket | 7 import socket |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 from infra_libs import experiments | |
| 10 from infra.services.service_manager import config_watcher | 11 from infra.services.service_manager import config_watcher |
| 11 from infra.services.service_manager import root_setup | 12 from infra.services.service_manager import root_setup |
| 12 | 13 |
| 13 import infra_libs | 14 import infra_libs |
| 14 | 15 |
| 15 | 16 |
| 16 class ServiceManager(infra_libs.BaseApplication): | 17 class ServiceManager(infra_libs.BaseApplication): |
| 17 DESCRIPTION = ('Starts and stops machine-wide infra services with arguments ' | 18 DESCRIPTION = ('Starts and stops machine-wide infra services with arguments ' |
| 18 'from config files') | 19 'from config files') |
| 19 | 20 |
| 20 def add_argparse_options(self, parser): | 21 def add_argparse_options(self, parser): |
| 21 super(ServiceManager, self).add_argparse_options(parser) | 22 super(ServiceManager, self).add_argparse_options(parser) |
| 22 | 23 |
| 23 if sys.platform == 'win32': | 24 if sys.platform == 'win32': |
| 24 default_state_directory = 'C:\\chrome-infra\\service-state' | 25 default_state_directory = 'C:\\chrome-infra\\service-state' |
| 25 default_config_directory = 'C:\\chrome-infra\\service-config' | 26 default_config_directory = 'C:\\chrome-infra\\service-config' |
| 26 default_root_directory = 'C:\\infra-python' | 27 default_root_directory = 'C:\\infra-python' |
| 28 default_cloudtail_path = 'C:\\infra-tools\\cloudtail.exe' | |
|
Vadim Sh.
2015/09/23 17:40:21
I propose to bundle cloudtail executable with infr
Vadim Sh.
2015/09/24 01:37:31
There's a chance infra.git will have infra/bin/<bi
dsansome
2015/09/24 04:34:13
Sounds good! For now I'll bundle it in the infra_
| |
| 27 else: | 29 else: |
| 28 default_state_directory = '/var/run/infra-services' | 30 default_state_directory = '/var/run/infra-services' |
| 29 default_config_directory = '/etc/infra-services' | 31 default_config_directory = '/etc/infra-services' |
| 30 default_root_directory = '/opt/infra-python' | 32 default_root_directory = '/opt/infra-python' |
| 33 default_cloudtail_path = '/opt/infra-tools/cloudtail' | |
| 31 | 34 |
| 32 parser.add_argument( | 35 parser.add_argument( |
| 33 '--state-directory', | 36 '--state-directory', |
| 34 default=default_state_directory, | 37 default=default_state_directory, |
| 35 help='directory to store PID files (default %(default)s)') | 38 help='directory to store PID files (default %(default)s)') |
| 36 parser.add_argument( | 39 parser.add_argument( |
| 37 '--config-directory', | 40 '--config-directory', |
| 38 default=default_config_directory, | 41 default=default_config_directory, |
| 39 help='directory to read JSON config files (default %(default)s)') | 42 help='directory to read JSON config files (default %(default)s)') |
| 40 parser.add_argument( | 43 parser.add_argument( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 52 default=10, | 55 default=10, |
| 53 help='how frequently (in seconds) to restart failed services') | 56 help='how frequently (in seconds) to restart failed services') |
| 54 | 57 |
| 55 parser.add_argument( | 58 parser.add_argument( |
| 56 '--root-setup', | 59 '--root-setup', |
| 57 action='store_true', | 60 action='store_true', |
| 58 help='if this is set service_manager will run once to initialise ' | 61 help='if this is set service_manager will run once to initialise ' |
| 59 'configs in /etc and then exit immediately. Used on GCE bots to ' | 62 'configs in /etc and then exit immediately. Used on GCE bots to ' |
| 60 'bootstrap service_manager') | 63 'bootstrap service_manager') |
| 61 | 64 |
| 65 parser.add_argument( | |
| 66 '--cloudtail-experiment-percent', | |
| 67 type=int, default=0, | |
| 68 help='Probability of tailing log files of started services to cloud ' | |
| 69 'logging using cloudtail') | |
| 70 parser.add_argument( | |
| 71 '--cloudtail-path', | |
| 72 default=default_cloudtail_path, | |
| 73 help='Path to the cloudtail binary') | |
| 74 | |
| 62 parser.set_defaults( | 75 parser.set_defaults( |
| 63 ts_mon_target_type='task', | 76 ts_mon_target_type='task', |
| 64 ts_mon_task_service_name='service_manager', | 77 ts_mon_task_service_name='service_manager', |
| 65 ts_mon_task_job_name=socket.getfqdn(), | 78 ts_mon_task_job_name=socket.getfqdn(), |
| 66 ) | 79 ) |
| 67 | 80 |
| 68 def main(self, opts): | 81 def main(self, opts): |
| 69 if opts.root_setup: | 82 if opts.root_setup: |
| 70 return root_setup.root_setup() | 83 return root_setup.root_setup() |
| 71 | 84 |
| 85 cloudtail_active = experiments.is_active_for_host( | |
| 86 'cloudtail', opts.cloudtail_experiment_percent) | |
| 87 | |
| 72 watcher = config_watcher.ConfigWatcher( | 88 watcher = config_watcher.ConfigWatcher( |
| 73 opts.config_directory, | 89 opts.config_directory, |
| 74 opts.config_poll_interval, | 90 opts.config_poll_interval, |
| 75 opts.service_poll_interval, | 91 opts.service_poll_interval, |
| 76 opts.state_directory, | 92 opts.state_directory, |
| 77 opts.root_directory) | 93 opts.root_directory, |
| 94 opts.cloudtail_path if cloudtail_active else None) | |
| 78 | 95 |
| 79 def sigint_handler(_signal, _frame): | 96 def sigint_handler(_signal, _frame): |
| 80 watcher.stop() | 97 watcher.stop() |
| 81 | 98 |
| 82 previous_sigint_handler = signal.signal(signal.SIGINT, sigint_handler) | 99 previous_sigint_handler = signal.signal(signal.SIGINT, sigint_handler) |
| 83 watcher.run() | 100 watcher.run() |
| 84 signal.signal(signal.SIGINT, previous_sigint_handler) | 101 signal.signal(signal.SIGINT, previous_sigint_handler) |
| 85 | 102 |
| 86 | 103 |
| 87 if __name__ == '__main__': | 104 if __name__ == '__main__': |
| 88 ServiceManager().run() | 105 ServiceManager().run() |
| 89 | 106 |
| OLD | NEW |