forked from uncloud/uncloud
68 lines
2.1 KiB
Python
Executable file
68 lines
2.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
import argparse
|
|
import logging
|
|
import importlib
|
|
import multiprocessing as mp
|
|
import sys
|
|
|
|
from logging.handlers import SysLogHandler
|
|
from uncloud.configure.main import configure_parser
|
|
|
|
from uncloud import UncloudException
|
|
|
|
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)
|
|
|
|
parent_parser = argparse.ArgumentParser(add_help=False)
|
|
parent_parser.add_argument("--debug", "-d", action='store_true')
|
|
|
|
arg_parser = argparse.ArgumentParser()
|
|
|
|
subparsers = arg_parser.add_subparsers(dest="command")
|
|
|
|
api_parser = subparsers.add_parser("api", parents=[parent_parser])
|
|
host_parser = subparsers.add_parser("host")
|
|
host_parser.add_argument("--hostname", required=True)
|
|
|
|
scheduler_parser = subparsers.add_parser("scheduler")
|
|
filescanner_parser = subparsers.add_parser("filescanner")
|
|
imagescanner_parser = subparsers.add_parser("imagescanner")
|
|
metadata_parser = subparsers.add_parser("metadata")
|
|
config_parser = subparsers.add_parser("configure")
|
|
|
|
configure_parser(config_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)
|