diff --git a/scripts/ucloud b/scripts/ucloud index d700d79..1bb752b 100755 --- a/scripts/ucloud +++ b/scripts/ucloud @@ -18,8 +18,6 @@ if __name__ == "__main__": args = arg_parser.parse_args() try: - check() - if args.component == 'api': from ucloud.api.main import main diff --git a/ucloud/host/main.py b/ucloud/host/main.py index ccf0a8d..ca68351 100755 --- a/ucloud/host/main.py +++ b/ucloud/host/main.py @@ -71,8 +71,17 @@ def maintenance(host): if _vm: running_vms.remove(_vm) +def check(): + if env_vars.get('STORAGE_BACKEND') == 'filesystem' and not isdir(env_vars.get('VM_DIR')): + print("You have set STORAGE_BACKEND to filesystem. So, the vm directory mentioned" + " in .env file must exists. But, it don't.") + sys.exit(1) + + def main(hostname): + check() + heartbeat_updating_process = mp.Process(target=update_heartbeat, args=(hostname,)) host_pool = HostPool(etcd_client, env_vars.get('HOST_PREFIX')) diff --git a/ucloud/imagescanner/main.py b/ucloud/imagescanner/main.py index 20ce9d5..6ff01f8 100755 --- a/ucloud/imagescanner/main.py +++ b/ucloud/imagescanner/main.py @@ -18,6 +18,19 @@ def qemu_img_type(path): qemu_img_info = json.loads(qemu_img_info.decode("utf-8")) return qemu_img_info["format"] +def check(): + """ check whether settings are sane, refuse to start if they aren't """ + if env_vars.get('STORAGE_BACKEND') == 'filesystem' and not isdir(env_vars.get('IMAGE_DIR')): + print("You have set STORAGE_BACKEND to filesystem, but " + "{} does not exist. Refusing to start".format(env_vars.get('IMAGE_DIR'))) + sys.exit(1) + + try: + subprocess.check_output(['which', 'qemu-img']) + except Exception: + print("qemu-img missing") + sys.exit(1) + def main(): # We want to get images entries that requests images to be created diff --git a/ucloud/sanity_checks.py b/ucloud/sanity_checks.py deleted file mode 100644 index 143f767..0000000 --- a/ucloud/sanity_checks.py +++ /dev/null @@ -1,33 +0,0 @@ -import sys -import subprocess as sp - -from os.path import isdir -from ucloud.config import env_vars - - -def check(): - ######################### - # ucloud-image-scanner # - ######################### - if env_vars.get('STORAGE_BACKEND') == 'filesystem' and not isdir(env_vars.get('IMAGE_DIR')): - print("You have set STORAGE_BACKEND to filesystem. So," - "the {} must exists. But, it don't".format(env_vars.get('IMAGE_DIR'))) - sys.exit(1) - - try: - sp.check_output(['which', 'qemu-img']) - except Exception: - print("qemu-img missing") - sys.exit(1) - - ############### - # ucloud-host # - ############### - - if env_vars.get('STORAGE_BACKEND') == 'filesystem' and not isdir(env_vars.get('VM_DIR')): - print("You have set STORAGE_BACKEND to filesystem. So, the vm directory mentioned" - " in .env file must exists. But, it don't.") - sys.exit(1) - -if __name__ == "__main__": - check() \ No newline at end of file