2019-12-07 11:58:51 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
2019-12-08 11:28:25 +00:00
|
|
|
import importlib
|
|
|
|
import sys
|
2019-12-08 11:59:18 +00:00
|
|
|
import os
|
2019-12-14 15:23:31 +00:00
|
|
|
import multiprocessing as mp
|
|
|
|
|
2019-12-08 11:28:25 +00:00
|
|
|
|
|
|
|
COMMANDS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata']
|
2019-12-07 11:58:51 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2019-12-14 15:23:31 +00:00
|
|
|
logging.basicConfig(level=logging.DEBUG,
|
|
|
|
format='%(pathname)s:%(lineno)d -- %(levelname)-8s %(message)s',
|
|
|
|
filename='/var/log/ucloud.log', filemode='a')
|
|
|
|
|
|
|
|
logger = logging.getLogger("ucloud")
|
2019-12-08 11:28:25 +00:00
|
|
|
|
2019-12-07 11:58:51 +00:00
|
|
|
arg_parser = argparse.ArgumentParser(prog='ucloud',
|
|
|
|
description='Open Source Cloud Management Software')
|
2019-12-08 11:59:18 +00:00
|
|
|
arg_parser.add_argument('-c', '--conf-dir', help="Configuration directory")
|
2019-12-08 11:28:25 +00:00
|
|
|
arg_parser.add_argument('component', choices=COMMANDS)
|
2019-12-07 11:58:51 +00:00
|
|
|
arg_parser.add_argument('component_args', nargs='*')
|
|
|
|
args = arg_parser.parse_args()
|
|
|
|
|
2019-12-08 13:15:36 +00:00
|
|
|
if args.conf_dir:
|
|
|
|
os.environ['UCLOUD_CONF_DIR'] = args.conf_dir
|
|
|
|
|
2019-12-07 11:58:51 +00:00
|
|
|
try:
|
2019-12-14 15:23:31 +00:00
|
|
|
mp.set_start_method('spawn')
|
2019-12-08 11:28:25 +00:00
|
|
|
name = args.component
|
|
|
|
mod = importlib.import_module("ucloud.{}.main".format(name))
|
|
|
|
main = getattr(mod, "main")
|
2019-12-14 15:23:31 +00:00
|
|
|
main(*args.component_args)
|
2019-12-07 11:58:51 +00:00
|
|
|
|
|
|
|
except Exception as e:
|
2019-12-14 15:23:31 +00:00
|
|
|
logger.exception(e)
|
2019-12-07 13:15:48 +00:00
|
|
|
print(e)
|