uncloud/scripts/ucloud

39 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
import logging
import importlib
import sys
import os
import multiprocessing as mp
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")
arg_parser = argparse.ArgumentParser(prog='ucloud',
description='Open Source Cloud Management Software')
arg_parser.add_argument('-c', '--conf-dir', help="Configuration directory")
arg_parser.add_argument('component', choices=COMMANDS)
arg_parser.add_argument('component_args', nargs='*')
args = arg_parser.parse_args()
if args.conf_dir:
os.environ['UCLOUD_CONF_DIR'] = args.conf_dir
try:
mp.set_start_method('spawn')
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)