summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-23 18:34:45 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-23 18:34:58 +0200
commit08ac2799b04a6326c26d1c22f784270f6bad7f44 (patch)
tree675f785ff0e6885293baeb7f1178658b18442160 /bin
parentf5b678df70394a6ecf91bb353841c0441a9e2c7a (diff)
downloadblog-08ac2799b04a6326c26d1c22f784270f6bad7f44.tar.gz
blog-08ac2799b04a6326c26d1c22f784270f6bad7f44.tar.bz2
blog-08ac2799b04a6326c26d1c22f784270f6bad7f44.zip
make build system faster and saner
Diffstat (limited to 'bin')
-rw-r--r--bin/taler-merchant-blog112
1 files changed, 112 insertions, 0 deletions
diff --git a/bin/taler-merchant-blog b/bin/taler-merchant-blog
new file mode 100644
index 0000000..9e567d5
--- /dev/null
+++ b/bin/taler-merchant-blog
@@ -0,0 +1,112 @@
+#!/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 <http://www.gnu.org/licenses/>
+#
+# @author Florian Dold
+# @file Standalone script to run the blog.
+
+import logging
+import argparse
+import sys
+import os
+import site
+from talerblog.talerconfig import TalerConfig
+
+## @cond
+LOGGER = logging.getLogger(__name__)
+
+# No perfect match to our logging format, but good enough ...
+UWSGI_LOGFMT = "%(ltime) %(proto) %(method) %(uri) %(proto) => %(status)"
+## @endcond
+
+
+##
+# 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(args):
+ port = args.port
+ if port is None:
+ port = TC["blog"]["http_port"].value_int(required=True)
+ spec = ":%d" % (port,)
+ os.execlp("uwsgi", "uwsgi",
+ "--master",
+ "--die-on-term",
+ "--log-format", UWSGI_LOGFMT,
+ "--http", spec,
+ "--module", "talerblog.blog:app")
+
+##
+# 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(args):
+ del args # pacify PEP checkers
+ serve_uwsgi = TC["blog"]["uwsgi_serve"].value_string(required=True).lower()
+ params = ["uwsgi", "uwsgi",
+ "--master",
+ "--die-on-term",
+ "--log-format", UWSGI_LOGFMT,
+ "--wsgi-file", "talerblog.blog:app",
+ "--cache2", "name=paid_articles,items=500"]
+ if serve_uwsgi == "tcp":
+ port = TC["blog"]["uwsgi_port"].value_int(required=True)
+ spec = ":%d" % (port,)
+ params.extend(["--socket", spec])
+ elif serve_uwsgi == "unix":
+ spec = TC["blog"]["uwsgi_unixpath"].value_filename(required=True)
+ mode = TC["blog"]["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)
+
+## @cond
+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()
+## @endcond
+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
+
+TC = TalerConfig.from_file(os.environ.get("TALER_CONFIG_FILE"))
+ARGS.func(ARGS)