gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-deployment] 01/02: taler-local


From: gnunet
Subject: [taler-deployment] 01/02: taler-local
Date: Sun, 14 Nov 2021 15:28:47 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository deployment.

commit 8c21fd6b30a570979993dca3b8729e153b81dccb
Author: ms <ms@taler.net>
AuthorDate: Sun Nov 14 14:29:20 2021 +0100

    taler-local
    
    launching exchange and merchant with systemd
---
 bin/WIP/taler-local | 122 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 114 insertions(+), 8 deletions(-)

diff --git a/bin/WIP/taler-local b/bin/WIP/taler-local
index 56fc938..d9d7378 100755
--- a/bin/WIP/taler-local
+++ b/bin/WIP/taler-local
@@ -52,6 +52,8 @@ from werkzeug.exceptions import HTTPException
 
 
 TALER_ROOT_DIR = Path.home() / ".taler"
+TALER_PREFIX = Path.home() / ".local"
+
 # Print No Newline.
 def print_nn(msg):
     print(msg, end="")
@@ -101,9 +103,8 @@ def update_checkout(r: Repo, p: Path):
 
 
 def default_configure(*extra):
-    pfx = Path.home() / ".local"
     extra_list = list(extra)
-    subprocess.run(["./configure", f"--prefix={pfx}"] + extra_list, check=True)
+    subprocess.run(["./configure", f"--prefix={TALER_PREFIX}"] + extra_list, 
check=True)
 
 def pyconfigure(*extra):
     """For python programs, --prefix doesn't work."""
@@ -545,6 +546,12 @@ class TalerReverseProxy(Flask):
     def get_app(self):
         return self
     
+
+LOG_DIR = TALER_ROOT_DIR / "logs"
+UNIX_SOCKETS_DIR = TALER_ROOT_DIR / "sockets"
+REV_PROXY_NETLOC = "localhost:8080"
+REV_PROXY_PROTO = "http"
+
 @cli.command()
 def prepare():
 
@@ -720,10 +727,9 @@ def prepare():
 
     # Filesystem's paths
     CFG_OUTDIR = TALER_ROOT_DIR / "config"
-    UNIX_SOCKETS_DIR = TALER_ROOT_DIR / "sockets"
     TALER_RUNTIME_DIR = TALER_ROOT_DIR / "runtime"
     TALER_DATA_DIR = TALER_ROOT_DIR / "data"
-    LOG_DIR = TALER_ROOT_DIR / "logs"
+    SYSTEMD_UNIT_FILES_DIR = TALER_ROOT_DIR / "systemd-unit-files"
     
     # IBANs
     IBAN_EXCHANGE = "EX00000000000000000000"
@@ -744,10 +750,6 @@ def prepare():
     FRONTENDS_API_TOKEN = "secret-token:secret"
     TALER_MERCHANT_TOKEN = "secret-token:secret"
 
-    # Network locations
-    REV_PROXY_NETLOC = "localhost:8080"
-    REV_PROXY_PROTO = "http"
-
     # URLs
     REV_PROXY_URL = f"{REV_PROXY_PROTO}://{REV_PROXY_NETLOC}"
     SANDBOX_URL = REV_PROXY_URL + "/sandbox"
@@ -1574,5 +1576,109 @@ Logs: {rev_proxy.get_log_filename()}"
     print_nn("Stopping the reverse proxy...")
     rev_proxy.stop()
     print(" OK")
+    
+    # Put SystemD unit files into the prepare folder.
+    systemd_user_dir = Path.home() / ".config" / "systemd" / "user"
+
+    if not systemd_user_dir.exists():
+        systemd_user_dir.mkdir(parents=True, exist_ok=True)
+
+    if not SYSTEMD_UNIT_FILES_DIR.exists():
+        SYSTEMD_UNIT_FILES_DIR.mkdir(parents=True, exist_ok=True)
+
+    # Exchange unit file.
+    exchange_unit = open(SYSTEMD_UNIT_FILES_DIR / "exchange.service", "w")
+    exchange_unit.write("[Unit]\n")
+    exchange_unit.write('Description="Taler Exchange"\n')
+    exchange_unit.write("[Service]\n")
+    exchange_unit.write(
+        f"ExecStart={TALER_PREFIX}/bin/taler-exchange-httpd -c {CFG_OUTDIR / 
'taler.conf'}\n"
+    )
+    # Exchange RSA helper unit file.
+    exchange_rsa_unit = open(SYSTEMD_UNIT_FILES_DIR / 
"exchange-secmod-rsa.service", "w")
+    exchange_rsa_unit.write("[Unit]\n")
+    exchange_rsa_unit.write('Description="Taler Exchange RSA security 
module."\n')
+    exchange_rsa_unit.write("[Service]\n")
+    exchange_rsa_unit.write(
+        f"ExecStart={TALER_PREFIX}/bin/taler-exchange-secmod-rsa -c 
{CFG_OUTDIR / 'taler.conf'}\n"
+    )
+    exchange_rsa_unit.close()
+    # Exchange EDDSA helper unit file.
+    exchange_eddsa_unit = open(SYSTEMD_UNIT_FILES_DIR / 
"exchange-secmod-eddsa.service", "w")
+    exchange_eddsa_unit.write("[Unit]\n")
+    exchange_eddsa_unit.write('Description="Taler Exchange EDDSA security 
module."\n')
+    exchange_eddsa_unit.write("[Service]\n")
+    exchange_eddsa_unit.write(
+        f"ExecStart={TALER_PREFIX}/bin/taler-exchange-secmod-eddsa -c 
{CFG_OUTDIR / 'taler.conf'}\n"
+    )
+    exchange_eddsa_unit.close()
+    # Merchant unit file.
+    merchant_unit = open(SYSTEMD_UNIT_FILES_DIR / "merchant-backend.service", 
"w")
+    merchant_unit.write("[Unit]\n")
+    merchant_unit.write('Description="Taler Merchant Backend"\n')
+    merchant_unit.write("[Service]\n")
+    merchant_unit.write(
+        f"ExecStart={TALER_PREFIX}/bin/taler-merchant-httpd -c {CFG_OUTDIR / 
'taler.conf'}\n"
+    )
+
+    # Custom Postgres connection.
+    if os.environ.get("PGPORT"):
+        exchange_unit.write(f"EnvironmentFile={systemd_user_dir / 
'exchange.env'}")
+        merchant_unit.write(f"EnvironmentFile={systemd_user_dir / 
'merchant-backend.env'}")
+        with open(SYSTEMD_UNIT_FILES_DIR / "exchange.env", "w") as 
exchange_env:
+            exchange_env.write(f"PGPORT={os.environ.get('PGPORT')}")
+        with open(SYSTEMD_UNIT_FILES_DIR / "merchant-backend.env", "w") as 
merchant_env:
+            merchant_env.write(f"PGPORT={os.environ.get('PGPORT')}")
+        # Symlinking the environment files into the SystemD canonical user 
directory.
+        if not os.path.islink(systemd_user_dir / "exchange.env"):
+            os.symlink(exchange_env.name, systemd_user_dir / "exchange.env")
+        if not os.path.islink(systemd_user_dir / "merchant-backend.env"):
+            os.symlink(merchant_env.name, systemd_user_dir / 
"merchant-backend.env")
+
+    exchange_unit.close()
+    merchant_unit.close()
+
+    # Symlinking the unit files into the canonical SystemD user directory.
+    if not os.path.islink(systemd_user_dir / "exchange.service"):
+        os.symlink(exchange_unit.name, systemd_user_dir / "exchange.service")
+    if not os.path.islink(systemd_user_dir / "merchant-backend.service"):
+        os.symlink(merchant_unit.name, systemd_user_dir / 
"merchant-backend.service")
+    if not os.path.islink(systemd_user_dir / "exchange-secmod-rsa.service"):
+        os.symlink(exchange_rsa_unit.name, systemd_user_dir / 
"exchange-secmod-rsa.service")
+    if not os.path.islink(systemd_user_dir / "exchange-secmod-eddsa.service"):
+        os.symlink(exchange_eddsa_unit.name, systemd_user_dir / 
"exchange-secmod-eddsa.service")
+    # more units here..
+    print_nn("Reload SystemD...")
+    Command(["systemctl", "--user", "daemon-reload"]).run()
+    print(" OK")
+
+@cli.command()
+def launch():
+
+    subprocess.run(["systemctl", "--user", "start", "exchange.service"], 
check=True)
+    subprocess.run(["systemctl", "--user", "start", 
"exchange-secmod-rsa.service"], check=True)
+    subprocess.run(["systemctl", "--user", "start", 
"exchange-secmod-eddsa.service"], check=True)
+    subprocess.run(["systemctl", "--user", "start", 
"merchant-backend.service"], check=True)
+
+    rev_proxy = TalerReverseProxy(
+        LOG_DIR,
+        UNIX_SOCKETS_DIR,
+        REV_PROXY_PROTO,
+        REV_PROXY_NETLOC
+    )
+    netloc_parts = REV_PROXY_NETLOC.split(":")
+    rev_proxy.run(
+        host=netloc_parts[0],
+        port=netloc_parts[1],
+        debug=False
+    )
+    # Stop with CTRL+C
+    print_nn("Stopping the services...")
+    subprocess.run(["systemctl", "--user", "stop", 
"merchant-backend.service"], check=True)
+    subprocess.run(["systemctl", "--user", "stop", "exchange.service"], 
check=True)
+    subprocess.run(["systemctl", "--user", "stop", 
"exchange-secmod-rsa.service"], check=True)
+    subprocess.run(["systemctl", "--user", "stop", 
"exchange-secmod-eddsa.service"], check=True)
+    print(" OK")
+
 if __name__ == "__main__":
     cli()

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]