uncloud/scripts/uncloud

60 lines
1.9 KiB
Text
Raw Normal View History

#!/usr/bin/env python3
import logging
2020-01-03 13:38:59 +00:00
import sys
2019-12-08 11:28:25 +00:00
import importlib
2020-01-03 13:38:59 +00:00
import argparse
import multiprocessing as mp
2019-12-31 11:15:05 +00:00
from uncloud import UncloudException
2020-01-03 13:38:59 +00:00
from contextlib import suppress
2019-12-08 11:28:25 +00:00
2019-12-21 09:36:55 +00:00
def exception_hook(exc_type, exc_value, exc_traceback):
logging.getLogger(__name__).error(
'Uncaught exception',
exc_info=(exc_type, exc_value, exc_traceback)
)
2019-12-22 08:47:16 +00:00
sys.excepthook = exception_hook
2019-12-21 09:36:55 +00:00
if __name__ == '__main__':
# Setting up root logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
2019-12-21 09:36:55 +00:00
arg_parser = argparse.ArgumentParser()
2020-01-03 13:38:59 +00:00
subparsers = arg_parser.add_subparsers(dest='command')
2020-01-03 13:38:59 +00:00
parent_parser = argparse.ArgumentParser(add_help=False)
parent_parser.add_argument('--debug', '-d', action='store_true', default=False,
help='More verbose logging')
2019-12-31 14:35:49 +00:00
2020-01-03 13:38:59 +00:00
for component in ['api', 'scheduler', 'host', 'filescanner', 'imagescanner',
'metadata', 'configure', 'cli']:
mod = importlib.import_module('uncloud.{}.main'.format(component))
parser = getattr(mod, 'arg_parser')
subparsers.add_parser(name=parser.prog, parents=[parser, parent_parser])
2019-12-21 09:36:55 +00:00
args = arg_parser.parse_args()
if not args.command:
arg_parser.print_help()
else:
# if we start etcd in seperate process with default settings
# i.e inheriting few things from parent process etcd3 module
# errors out, so the following command configure multiprocessing
# module to not inherit anything from parent.
# mp.set_start_method('spawn')
2019-12-21 09:36:55 +00:00
arguments = vars(args)
try:
name = arguments.pop('command')
2020-01-03 13:38:59 +00:00
mod = importlib.import_module('uncloud.{}.main'.format(name))
main = getattr(mod, 'main')
2019-12-21 09:36:55 +00:00
main(**arguments)
2019-12-31 11:15:05 +00:00
except UncloudException as err:
logger.error(err)
sys.exit(1)
except Exception as err:
logger.exception(err)
sys.exit(1)