Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cli.py
Show All 14 Lines | |||||
@click.pass_context | @click.pass_context | ||||
def storage(ctx): | def storage(ctx): | ||||
'''Software Heritage Storage tools.''' | '''Software Heritage Storage tools.''' | ||||
pass | pass | ||||
@storage.command(name='rpc-serve') | @storage.command(name='rpc-serve') | ||||
@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('--host', default='0.0.0.0', | ||||
metavar='IP', show_default=True, | |||||
help="Host ip address to bind the server on") | |||||
@click.option('--port', default=5002, type=click.INT, | @click.option('--port', default=5002, type=click.INT, | ||||
metavar='PORT', show_default=True, | |||||
help="Binding port of the server") | help="Binding port of the server") | ||||
@click.option('--debug/--no-debug', default=True, | @click.option('--debug/--no-debug', default=True, | ||||
help="Indicates if the server should run in debug mode") | help="Indicates if the server should run in debug mode") | ||||
def serve(config_path, host, port, debug): | def serve(config_path, host, port, debug): | ||||
'''Software Heritage Storage RPC (standalone) server. | '''Software Heritage Storage RPC server. | ||||
Do NOT use this in a production environment. | Do NOT use this in a production environment. | ||||
''' | ''' | ||||
api_cfg = load_and_check_config(config_path, type='any') | api_cfg = load_and_check_config(config_path, type='any') | ||||
app.config.update(api_cfg) | app.config.update(api_cfg) | ||||
app.run(host, port=int(port), debug=bool(debug)) | app.run(host, port=int(port), debug=bool(debug)) | ||||
def main(): | def main(): | ||||
logging.basicConfig() | logging.basicConfig() | ||||
return serve(auto_envvar_prefix='SWH_STORAGE') | return serve(auto_envvar_prefix='SWH_STORAGE') | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |