diff --git a/swh/storage/api/server.py b/swh/storage/api/server.py --- a/swh/storage/api/server.py +++ b/swh/storage/api/server.py @@ -242,7 +242,8 @@ @click.command() @click.argument('config-path', required=1) @click.option('--host', default='0.0.0.0', help="Host to run the server") -@click.option('--port', default=5000, help="Binding port of ther server") +@click.option('--port', default=5000, type=click.INT, + help="Binding port of the server") @click.option('--debug/--nodebug', default=True, help="Indicates if the server should run in debug mode") def launch(config_path, host, port, debug): diff --git a/swh/storage/archiver/director.py b/swh/storage/archiver/director.py --- a/swh/storage/archiver/director.py +++ b/swh/storage/archiver/director.py @@ -5,23 +5,24 @@ import swh import logging +import click from datetime import datetime -from swh.core import hashutil +from swh.core import hashutil, config from swh.scheduler.celery_backend.config import app from . import tasks # NOQA DEFAULT_CONFIG = { - 'objstorage_path': '/tmp/swh-storage/objects', - 'batch_max_size': 50, - 'archival_max_age': 3600, - 'retention_policy': 2, - 'asynchronous': True, - - 'dbname': 'softwareheritage', - 'user': 'root' + 'objstorage_path': ('str', '/tmp/swh-storage/objects'), + 'batch_max_size': ('int', 50), + 'archival_max_age': ('int', 3600), + 'retention_policy': ('int', 2), + 'asynchronous': ('bool', True), + + 'dbname': ('str', 'softwareheritage'), + 'user': ('str', 'root') } task_name = 'swh.storage.archiver.tasks.SWHArchiverTask' @@ -216,3 +217,32 @@ else: raise ValueError("status must be either 'present', 'missing' " "or 'ongoing'") + + +@click.command() +@click.argument('config-path', required=1) +@click.option('--dbname', default=DEFAULT_CONFIG['dbname'][1], + help="Db name for the archiver to connect to") +@click.option('--user', default=DEFAULT_CONFIG['user'][1], + help="Username to connect to the db") +@click.option('--async/--sync', default=DEFAULT_CONFIG['asynchronous'][1], + help="Indicates if the archiver should run asynchronously") +def launch(config_path, dbname, user, async): + # The configuration have following priority : + # command line > file config > default config + cl_config = { + 'dbname': dbname, + 'user': user, + 'asynchronous': bool(async) + } + conf = config.read(config_path, DEFAULT_CONFIG) + conf.update(cl_config) + # Create connection data and run the archiver. + dbconn_string = 'dbname=%s user=%s' % (conf['dbname'], conf['user']) + archiver = ArchiverDirector(dbconn_string, conf) + logger.info("Starting an archival at", datetime.now()) + archiver.run() + + +if __name__ == '__main__': + launch() diff --git a/swh/storage/objstorage/api/server.py b/swh/storage/objstorage/api/server.py --- a/swh/storage/objstorage/api/server.py +++ b/swh/storage/objstorage/api/server.py @@ -59,9 +59,10 @@ @click.command() -@click.argument('Config-path', required=1) +@click.argument('config-path', required=1) @click.option('--host', default='0.0.0.0', help="Host to run the server") -@click.option('--port', default=5000, help="Server's port") +@click.option('--port', default=5000, type=click.INT, + help="Binding port of the server") @click.option('--debug/--nodebug', default=True, help="Indicates if the server should run in debug mode") def launch(config_path, host, port, debug):