forked from uncloud/uncloud
58 lines
1.9 KiB
Python
Executable file
58 lines
1.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import logging
|
|
import sys
|
|
import importlib
|
|
import argparse
|
|
import multiprocessing as mp
|
|
|
|
from uncloud import UncloudException
|
|
from contextlib import suppress
|
|
|
|
|
|
def exception_hook(exc_type, exc_value, exc_traceback):
|
|
logging.getLogger(__name__).error(
|
|
'Uncaught exception',
|
|
exc_info=(exc_type, exc_value, exc_traceback)
|
|
)
|
|
|
|
|
|
sys.excepthook = exception_hook
|
|
|
|
if __name__ == '__main__':
|
|
# Setting up root logger
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
arg_parser = argparse.ArgumentParser()
|
|
subparsers = arg_parser.add_subparsers(dest='command')
|
|
|
|
parent_parser = argparse.ArgumentParser(add_help=False)
|
|
parent_parser.add_argument('--debug', '-d', action='store_true', default=False,
|
|
help='More verbose logging')
|
|
|
|
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])
|
|
|
|
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')
|
|
arguments = vars(args)
|
|
try:
|
|
name = arguments.pop('command')
|
|
mod = importlib.import_module('uncloud.{}.main'.format(name))
|
|
main = getattr(mod, 'main')
|
|
main(**arguments)
|
|
except UncloudException as err:
|
|
logger.error(err)
|
|
except Exception as err:
|
|
logger.exception(err)
|