diff --git a/bin/ucloud b/bin/ucloud old mode 100644 new mode 100755 index 7be6b24..238789e --- a/bin/ucloud +++ b/bin/ucloud @@ -1,59 +1,33 @@ -#!/usr/bin/env python3 +#!/bin/sh +# -*- coding: utf-8 -*- +# +# 2012-2019 Nico Schottelius (nico-ucloud at schottelius.org) +# +# This file is part of ucloud. +# +# ucloud is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ucloud is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ucloud. If not, see . +# +# -import argparse -import multiprocessing as mp -import logging +# Wrapper for real script to allow execution from checkout +dir=${0%/*} -from os.path import join as join_path -from ucloud.sanity_checks import check +# Ensure version is present - the bundled/shipped version contains a static version, +# the git version contains a dynamic version +printf "VERSION = \"%s\"\n" "$(git describe)" > ${dir}/ucloud/version.py -if __name__ == "__main__": - arg_parser = argparse.ArgumentParser(prog='ucloud', - description='Open Source Cloud Management Software') - arg_parser.add_argument('component', - choices=['api', 'scheduler', 'host', - 'filescanner', 'imagescanner', - 'metadata']) - arg_parser.add_argument('component_args', nargs='*') - args = arg_parser.parse_args() +libdir=$(cd "${dir}/../" && pwd -P) +export PYTHONPATH="${libdir}" - logging.basicConfig( - level=logging.DEBUG, - filename=join_path("/", "etc", "ucloud", "log.txt"), - filemode="a", - format="%(name)s %(asctime)s: %(levelname)s - %(message)s", - datefmt="%d-%b-%y %H:%M:%S", - ) - try: - check() - - if args.component == 'api': - from ucloud.api.main import main - - main() - elif args.component == 'host': - from ucloud.host.main import main - - hostname = args.component_args - mp.set_start_method('spawn') - main(*hostname) - elif args.component == 'scheduler': - from ucloud.scheduler.main import main - - main() - elif args.component == 'filescanner': - from ucloud.filescanner.main import main - - main() - elif args.component == 'imagescanner': - from ucloud.imagescanner.main import main - - main() - elif args.component == 'metadata': - from ucloud.metadata.main import main - - main() - - except Exception as e: - logging.exception(e) - print(e) \ No newline at end of file +"$dir/../scripts/ucloud" "$@" diff --git a/scripts/ucloud b/scripts/ucloud new file mode 100644 index 0000000..7be6b24 --- /dev/null +++ b/scripts/ucloud @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import argparse +import multiprocessing as mp +import logging + +from os.path import join as join_path +from ucloud.sanity_checks import check + +if __name__ == "__main__": + arg_parser = argparse.ArgumentParser(prog='ucloud', + description='Open Source Cloud Management Software') + arg_parser.add_argument('component', + choices=['api', 'scheduler', 'host', + 'filescanner', 'imagescanner', + 'metadata']) + arg_parser.add_argument('component_args', nargs='*') + args = arg_parser.parse_args() + + logging.basicConfig( + level=logging.DEBUG, + filename=join_path("/", "etc", "ucloud", "log.txt"), + filemode="a", + format="%(name)s %(asctime)s: %(levelname)s - %(message)s", + datefmt="%d-%b-%y %H:%M:%S", + ) + try: + check() + + if args.component == 'api': + from ucloud.api.main import main + + main() + elif args.component == 'host': + from ucloud.host.main import main + + hostname = args.component_args + mp.set_start_method('spawn') + main(*hostname) + elif args.component == 'scheduler': + from ucloud.scheduler.main import main + + main() + elif args.component == 'filescanner': + from ucloud.filescanner.main import main + + main() + elif args.component == 'imagescanner': + from ucloud.imagescanner.main import main + + main() + elif args.component == 'metadata': + from ucloud.metadata.main import main + + main() + + except Exception as e: + logging.exception(e) + print(e) \ No newline at end of file