uncloud/scripts/ucloud

40 lines
1.2 KiB
Text
Raw Normal View History

#!/usr/bin/env python3
import argparse
import logging
2019-12-08 11:28:25 +00:00
import importlib
import sys
import os
import multiprocessing as mp
2019-12-08 11:28:25 +00:00
COMMANDS = ['api', 'scheduler', 'host', 'filescanner', 'imagescanner', 'metadata']
if __name__ == "__main__":
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
arg_parser = argparse.ArgumentParser(prog='ucloud',
description='Open Source Cloud Management Software')
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)
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
try:
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")
main(*args.component_args)
except Exception as e:
logger.exception(e)
print(e)