summaryrefslogtreecommitdiff
path: root/taler-merchant-donations.in
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2017-11-24 17:33:01 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2017-11-24 17:33:01 +0100
commite103f75919721af3bd02d40e5b022a6426d4c460 (patch)
tree8ce7c20c324402a75cc7f09a547f3e838499062a /taler-merchant-donations.in
parent47bedadb4ecfd0740726bc21ecbfb25fd8802abc (diff)
downloaddonations-e103f75919721af3bd02d40e5b022a6426d4c460.tar.gz
donations-e103f75919721af3bd02d40e5b022a6426d4c460.tar.bz2
donations-e103f75919721af3bd02d40e5b022a6426d4c460.zip
bootstrap/wsgi/launcher
Diffstat (limited to 'taler-merchant-donations.in')
-rw-r--r--taler-merchant-donations.in82
1 files changed, 82 insertions, 0 deletions
diff --git a/taler-merchant-donations.in b/taler-merchant-donations.in
new file mode 100644
index 0000000..8613d43
--- /dev/null
+++ b/taler-merchant-donations.in
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+
+"""
+Stand-alone script to manage the GNU Taler donations frontend.
+"""
+
+import argparse
+import sys
+import os
+import site
+
+
+os.environ.setdefault("TALER_PREFIX", "@prefix@")
+site.addsitedir("%s/lib/python%d.%d/site-packages" % (
+ "@prefix@",
+ sys.version_info.major,
+ sys.version_info.minor))
+
+from talerdonations.talerconfig import TalerConfig
+import logging
+logger = logging.getLogger(__name__)
+
+# No perfect match to our logging format, but good enough ...
+uwsgi_logfmt = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)"
+
+def handle_serve_http(args):
+ tc = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE"))
+ port = args.port
+ if port is None:
+ port = tc["donations"]["http_port"].value_int(required=True)
+ spec = ":%d" % (port,)
+ os.execlp("uwsgi", "uwsgi",
+ "--master",
+ "--die-on-term",
+ "--log-format", uwsgi_logfmt,
+ "--http", spec,
+ "--wsgi-file", "@prefix@/share/taler/frontend-donations.wsgi")
+
+def handle_serve_uwsgi(args):
+ tc = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE"))
+ serve_uwsgi = tc["donations"]["uwsgi_serve"].value_string(required=True).lower()
+ params = ["uwsgi", "uwsgi",
+ "--master",
+ "--die-on-term",
+ "--log-format", uwsgi_logfmt,
+ "--wsgi-file", "@prefix@/share/taler/frontend-donations.wsgi"]
+ if serve_uwsgi == "tcp":
+ port = tc["donations"]["uwsgi_port"].value_int(required=True)
+ spec = ":%d" % (port,)
+ params.extend(["--socket", spec])
+ elif serve_uwsgi == "unix":
+ spec = tc["donations"]["uwsgi_unixpath"].value_filename(required=True)
+ mode = tc["donations"]["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)
+
+
+
+parser = argparse.ArgumentParser()
+parser.set_defaults(func=None)
+parser.add_argument('--config', '-c', help="configuration file to use", metavar="CONFIG", type=str, dest="config", default=None)
+sub = parser.add_subparsers()
+
+p = sub.add_parser('serve-http', help="Serve over HTTP")
+p.add_argument("--port", "-p", dest="port", type=int, default=None, metavar="PORT")
+p.set_defaults(func=handle_serve_http)
+
+p = sub.add_parser('serve-uwsgi', help="Serve over UWSGI")
+p.set_defaults(func=handle_serve_uwsgi)
+
+args = parser.parse_args()
+if getattr(args, 'func', None) is None:
+ parser.print_help()
+ sys.exit(1)
+
+if args.config is not None:
+ os.environ["TALER_CONFIG_FILE"] = args.config
+
+args.func(args)