diff options
author | ms <ms@taler.net> | 2021-11-15 21:40:14 +0100 |
---|---|---|
committer | ms <ms@taler.net> | 2021-11-15 21:40:14 +0100 |
commit | 6844bf021208e88085b877cc9603196df55c0242 (patch) | |
tree | cc408c07c4e53f1ab97b2f0469466b8aa2a5e28e /talermerchantdemos | |
parent | 4da846050c5366d070c597310ac7e091da75ac5a (diff) | |
download | taler-merchant-demos-6844bf021208e88085b877cc9603196df55c0242.tar.gz taler-merchant-demos-6844bf021208e88085b877cc9603196df55c0242.tar.bz2 taler-merchant-demos-6844bf021208e88085b877cc9603196df55c0242.zip |
Extend config.
Give possibility to serve HTTP via Unix domain sockets.
Diffstat (limited to 'talermerchantdemos')
-rw-r--r-- | talermerchantdemos/cli.py | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/talermerchantdemos/cli.py b/talermerchantdemos/cli.py index fd836c6..78f9049 100644 --- a/talermerchantdemos/cli.py +++ b/talermerchantdemos/cli.py @@ -57,7 +57,7 @@ def handle_serve_uwsgi(config, which_shop): "talermerchantdemos.{}:app".format(which_shop), "--need-app", "--cache2", - "name=paid_articles,items=500", + "name=paid_articles,items=500" ] if serve_uwsgi == "tcp": port = config[which_shop]["uwsgi_port"].value_int(required=True) @@ -85,33 +85,47 @@ def handle_serve_uwsgi(config, which_shop): # # @param args command line options. def handle_serve_http(config, which_shop, port=None): - if port is None: - port = config[which_shop]["http_port"].value_int(required=True) - if port is None: - print("'http_port' configuration option is missing") - exit(1) - spec = ":%d" % (port,) + params = [ + "uwsgi", + "uwsgi", + *arg_load_python, + "--master", + "--die-on-term", + "--log-format", + UWSGI_LOGFMT, + "--module", + "talermerchantdemos.{}:app".format(which_shop), + ] + + # Takes precedence. + if port: + http_serve = "tcp" + else: + http_serve = config[which_shop]["http_serve"].value_string( + required=False, + default="tcp" + ).lower() + + if http_serve == "tcp": + port_launch = config[which_shop]["http_port"].value_int(required=False) if not port else port + if not port_launch: + sys.stderr.write("Port number wasn't found in config and in arguments.") + exit(1) + params.extend(["--http", f":{port_launch}"]) + + if http_serve == "unix": + path = config[which_shop]["http_unixpath"].value_filename(required=True) + mode = config[which_shop]["http_unixpath_mode"].value_filename(required=True) + params.extend(["--http-socket", path]) + params.extend(["--chmod-socket=" + mode]) + os.makedirs(os.path.dirname(path), exist_ok=True) + try: - os.execlp( - "uwsgi", - "uwsgi", - *arg_load_python, - "--master", - "--die-on-term", - "--log-format", - UWSGI_LOGFMT, - "--http", - spec, - "--module", - "talermerchantdemos.{}:app".format(which_shop), - ) + os.execlp(*params) except: - sys.stderr.write( - "Failed to start uwsgi. Please make sure to install uwsgi for Python3." - ) + sys.stderr.write("Failed to start uwsgi. Please make sure to install uwsgi for Python3.") sys.exit(1) - def handle_serve_from_config(config_obj, which_shop): try: if ( |