From 2d97ecc2c1ac605ca49e8a866b309daaeb7a831c Mon Sep 17 00:00:00 2001 From: MS Date: Wed, 22 Jul 2020 14:53:45 +0200 Subject: Installing the Blog --- bin/.taler-merchant-demos.swp | Bin 0 -> 20480 bytes bin/taler-merchant-demos | 102 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 bin/.taler-merchant-demos.swp create mode 100755 bin/taler-merchant-demos (limited to 'bin') diff --git a/bin/.taler-merchant-demos.swp b/bin/.taler-merchant-demos.swp new file mode 100644 index 0000000..3f5655a Binary files /dev/null and b/bin/.taler-merchant-demos.swp differ diff --git a/bin/taler-merchant-demos b/bin/taler-merchant-demos new file mode 100755 index 0000000..42fe35a --- /dev/null +++ b/bin/taler-merchant-demos @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 + +## +# This file is part of TALER +# (C) 2017 INRIA +# +# TALER is free software; you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public +# License as published by the Free Software Foundation; either +# version 3, or (at your option) any later version. +# +# TALER 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 TALER; see the file COPYING. If not, +# see +# +# @author Florian Dold +# @file Standalone script to run the blog. + +import click +import logging +import argparse +import sys +import os +import site +from taler.util.talerconfig import TalerConfig + +LOGGER = logging.getLogger(__name__) +# No perfect match to our logging format, but good enough ... +UWSGI_LOGFMT = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)" + +## +# This function interprets the 'serve-uwsgi' subcommand. +# The effect is to launch the blog UWSGI service. This +# type of service is usually used when the HTTP blog interface +# is accessed via a reverse proxy (like Nginx, for example). +# +# @param command line options. +def handle_serve_uwsgi(config, whichShop): + serve_uwsgi = config[whichShop]["uwsgi_serve"].value_string(required=True).lower() + params = ["uwsgi", "uwsgi", + "--master", + "--die-on-term", + "--log-format", UWSGI_LOGFMT, + "--module", "talermerchantdemos.{}:app".format(whichShop), + "--cache2", "name=paid_articles,items=500"] + if serve_uwsgi == "tcp": + port = config[whichShop]["uwsgi_port"].value_int(required=True) + spec = ":%d" % (port,) + params.extend(["--socket", spec]) + elif serve_uwsgi == "unix": + spec = config[whichShop]["uwsgi_unixpath"].value_filename(required=True) + mode = config[whichShop]["uwsgi_unixpath_mode"].value_filename(required=True) + params.extend(["--socket", spec]) + params.extend(["--chmod-socket="+mode]) + os.makedirs(os.path.dirname(spec), exist_ok=True) + logging.info("launching uwsgi with argv %s", params[1:]) + os.execlp(*params) + +## +# This function interprets the 'serve-http' subcommand. +# The effect it to launch the blog HTTP service. +# +# @param args command line options. +def handle_serve_http(config, whichShop, port=None): + if port is None: + port = config[whichShop]["http_port"].value_int(required=True) + spec = ":%d" % (port,) + os.execlp("uwsgi", "uwsgi", + "--master", + "--die-on-term", + "--log-format", UWSGI_LOGFMT, + "--http", spec, + "--module", "talermerchantdemos.{}:app".format(whichShop)) + +@click.group(help="Global launcher of Taler demo stores") +@click.option("--config", help="Configuration file", required=False) +@click.pass_context +def cli(ctx, config): + if config: + os.environ["TALER_CONFIG_FILE"] = config + config_obj = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE")) + ctx.obj = dict(config=config_obj) + +@cli.command(help="Run the blog") +@click.pass_obj +@click.option("--serve-http", help="Serve via HTTP", is_flag=True, required=False) +@click.option("--port", help="HTTP port to serve (if not given, it's picked from config)", required=False, type=int) +@click.option("--serve-uwsgi", help="Serve via UWSGI (default)", required=False) +def blog(obj, serve_http, port, serve_uwsgi): + assert(obj.get("config")) + + if serve_http: # port was given + handle_serve_http(obj["config"], "blog", port) + return + handle_serve_uwsgi(obj["config"], "blog") + +cli() -- cgit v1.2.3