From 42b388c91339bf7e9d67c1ee9b94fa1bafb6a644 Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Wed, 26 Oct 2022 16:36:22 +0200 Subject: [PATCH 01/10] Update to WebTop 5.8.3 --- webtop5-build/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webtop5-build/VERSION b/webtop5-build/VERSION index 15b6531a..4e43e45f 100644 --- a/webtop5-build/VERSION +++ b/webtop5-build/VERSION @@ -1 +1 @@ -wt-5.18.2 +wt-5.18.3 From 5386d2a70b9778d90974995e6a2ea7bb8634a53c Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Thu, 17 Nov 2022 17:43:04 +0100 Subject: [PATCH 02/10] build-images.sh: fix ui build in node 18 --- build-images.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-images.sh b/build-images.sh index 167c0eee..8eedf60c 100644 --- a/build-images.sh +++ b/build-images.sh @@ -133,11 +133,11 @@ container=$(buildah from scratch) # Reuse existing nodebuilder-webtop container, to speed up builds if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-webtop; then echo "Pulling NodeJS runtime..." - buildah from --name nodebuilder-webtop -v "${PWD}:/usr/src:Z" docker.io/library/node:lts + buildah from --name nodebuilder-webtop -v "${PWD}:/usr/src:Z" docker.io/library/node:18-slim fi echo "Build static UI files with node..." -buildah run nodebuilder-webtop sh -c "cd /usr/src/ui && yarn install && yarn build" +buildah run --env="NODE_OPTIONS=--openssl-legacy-provider" nodebuilder-webtop sh -c "cd /usr/src/ui && yarn install && yarn build" # Add imageroot directory to the container image buildah add "${container}" imageroot /imageroot From 86bda91152696880235a51cebf811b69712c8497 Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Thu, 17 Nov 2022 16:53:55 +0100 Subject: [PATCH 03/10] Add `configure-module` action The webtop instance must be accessible via a configured hostname. --- imageroot/actions/configure-module/20config | 62 ++++++++++++ .../80enable_service} | 0 .../configure-module/validate-input.json | 22 +++++ imageroot/actions/create-module/20configure | 99 ------------------- imageroot/actions/destroy-module/20destroy | 35 ------- 5 files changed, 84 insertions(+), 134 deletions(-) create mode 100755 imageroot/actions/configure-module/20config rename imageroot/actions/{create-module/80start_services => configure-module/80enable_service} (100%) create mode 100644 imageroot/actions/configure-module/validate-input.json delete mode 100755 imageroot/actions/create-module/20configure diff --git a/imageroot/actions/configure-module/20config b/imageroot/actions/configure-module/20config new file mode 100755 index 00000000..faf1c14e --- /dev/null +++ b/imageroot/actions/configure-module/20config @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2022 Nethesis S.r.l. +# http://www.nethesis.it - nethserver@nethesis.it +# +# This script is part of NethServer. +# +# NethServer is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, +# or any later version. +# +# NethServer 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 NethServer. If not, see COPYING. +# + +# +# Create a virtual host configuration +# Input example: +# {"instance": "module1", "url": "http://127.0.0.0:2000", "path": "/foo", "http2https": true} +# + +import json +import sys +import os +import agent + +# Try to parse the stdin as JSON. +# If parsing fails, output everything to stderr +data = json.load(sys.stdin) + +agent_id = os.getenv("AGENT_ID", "") +if not agent_id: + raise Exception("AGENT_ID not found inside the environemnt") + +# Connect to redis +r = agent.redis_connect(privileged=True).pipeline() + +if data.get("hostname") is not None: + if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): + agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) + + # Configure Traefik to route WebTop's host requests to the webtop module + response = agent.tasks.run( + agent_id=agent.resolve_agent_id('traefik@node'), + action='set-route', + data={ + 'instance': os.environ['MODULE_ID'], + 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], + 'http2https': True, + 'lets_encrypt': False, + 'host': data['hostname'], + }, + ) + # Check if traefik configuration has been successfull + agent.assert_exp(response['exit_code'] == 0) diff --git a/imageroot/actions/create-module/80start_services b/imageroot/actions/configure-module/80enable_service similarity index 100% rename from imageroot/actions/create-module/80start_services rename to imageroot/actions/configure-module/80enable_service diff --git a/imageroot/actions/configure-module/validate-input.json b/imageroot/actions/configure-module/validate-input.json new file mode 100644 index 00000000..4b9f6576 --- /dev/null +++ b/imageroot/actions/configure-module/validate-input.json @@ -0,0 +1,22 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "configure-module input", + "$id": "http://schema.nethserver.org/webtop/configure-route-input.json", + "description": "Configure webtop", + "examples": [ + { + "hostname": "example.com" + } + ], + "type": "object", + "properties": { + "hostname": { + "type": "string", + "format": "hostname", + "title": "Hostname of the WebTop instance", + "examples": [ + "example.com" + ] + } + } +} diff --git a/imageroot/actions/create-module/20configure b/imageroot/actions/create-module/20configure deleted file mode 100755 index 71f785ef..00000000 --- a/imageroot/actions/create-module/20configure +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python3 - -# -# Copyright (C) 2022 Nethesis S.r.l. -# http://www.nethesis.it - nethserver@nethesis.it -# -# This script is part of NethServer. -# -# NethServer is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, -# or any later version. -# -# NethServer 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 NethServer. If not, see COPYING. -# - -import json -import sys -import agent -import agent.tasks -import os - -request = json.load(sys.stdin) - -# Configure Traefik to route "/webtop" path requests to the webapp service -response = agent.tasks.run( - agent_id=agent.resolve_agent_id('traefik@node'), - action='set-route', - data={ - 'instance': os.environ['MODULE_ID'], - 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], - 'http2https': True, - 'lets_encrypt': False, - 'path': '/webtop', - }, -) - -# Check if traefik configuration has been successfull -agent.assert_exp(response['exit_code'] == 0) - - -# Configure Traefik to route "/webtop-dav" path requests to the webdav service -response = agent.tasks.run( - agent_id=agent.resolve_agent_id('traefik@node'), - action='set-route', - data={ - 'instance': f"{os.environ['MODULE_ID']}-webdav", - 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], - 'http2https': True, - 'lets_encrypt': False, - 'path': '/webtop-dav', - }, -) - -# Check if traefik configuration has been successfull -agent.assert_exp(response['exit_code'] == 0) - -response = agent.tasks.runp_brief([{ - "agent_id": agent.resolve_agent_id('traefik@node'), - "action": "set-route", - "data": { - 'instance': f"{os.environ['MODULE_ID']}-well-known-caldav", - 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], - 'http2https': True, - 'lets_encrypt': False, - 'path': '/.well-known/caldav', - }},{ - "agent_id": agent.resolve_agent_id('traefik@node'), - "action": "set-route", - "data": { - 'instance': f"{os.environ['MODULE_ID']}-well-known-carddav", - 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], - 'http2https': True, - 'lets_encrypt': False, - 'path': '/.well-known/carddav', - }}] -) - -# Configure Traefik to route "/Microsoft-Server-ActiveSync" path requests to the Exchange Active Sync service -response = agent.tasks.run( - agent_id=agent.resolve_agent_id('traefik@node'), - action='set-route', - data={ - 'instance': f"{os.environ['MODULE_ID']}-z-push", - 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], - 'http2https': True, - 'lets_encrypt': False, - 'path': '/Microsoft-Server-ActiveSync', - }, -) - -# Check if traefik configuration has been successfull -agent.assert_exp(response['exit_code'] == 0) diff --git a/imageroot/actions/destroy-module/20destroy b/imageroot/actions/destroy-module/20destroy index c4034d70..f3e903c7 100755 --- a/imageroot/actions/destroy-module/20destroy +++ b/imageroot/actions/destroy-module/20destroy @@ -48,38 +48,3 @@ response = agent.tasks.run( # Check if traefik configuration has been successfull agent.assert_exp(response['exit_code'] == 0) - -response = agent.tasks.run( - agent_id=agent.resolve_agent_id('traefik@node'), - action='delete-route', - data={ - 'instance': f"{os.environ['MODULE_ID']}-webdav", - }, -) - -# Check if traefik configuration has been successfull -agent.assert_exp(response['exit_code'] == 0) - -response = agent.tasks.runp_brief([{ - "agent_id": agent.resolve_agent_id('traefik@node'), - "action": "delete-route", - "data": { - 'instance': f"{os.environ['MODULE_ID']}-well-known-caldav", - }},{ - "agent_id": agent.resolve_agent_id('traefik@node'), - "action": "delete-route", - "data": { - 'instance': f"{os.environ['MODULE_ID']}-well-known-carddav", - }}] -) - -response = agent.tasks.run( - agent_id=agent.resolve_agent_id('traefik@node'), - action='delete-route', - data={ - 'instance': f"{os.environ['MODULE_ID']}-z-push", - }, -) - -# Check if traefik configuration has been successfull -agent.assert_exp(response['exit_code'] == 0) From 357e3a06f5f9aefdcdf524335df9c3dc32ce9f90 Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Tue, 22 Nov 2022 12:56:32 +0100 Subject: [PATCH 04/10] configure-module: start service before configure --- .../actions/configure-module/10start_service | 23 +++++++++++++++++++ .../actions/configure-module/80enable_service | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 imageroot/actions/configure-module/10start_service diff --git a/imageroot/actions/configure-module/10start_service b/imageroot/actions/configure-module/10start_service new file mode 100755 index 00000000..00850cc2 --- /dev/null +++ b/imageroot/actions/configure-module/10start_service @@ -0,0 +1,23 @@ +#!/bin/bash + +# +# Copyright (C) 2022 Nethesis S.r.l. +# http://www.nethesis.it - nethserver@nethesis.it +# +# This script is part of NethServer. +# +# NethServer is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, +# or any later version. +# +# NethServer 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 NethServer. If not, see COPYING. +# + +systemctl --user start webtop diff --git a/imageroot/actions/configure-module/80enable_service b/imageroot/actions/configure-module/80enable_service index eafe05d1..476c05cb 100755 --- a/imageroot/actions/configure-module/80enable_service +++ b/imageroot/actions/configure-module/80enable_service @@ -22,4 +22,4 @@ # If the control reaches this step, the service can be enabled and started -systemctl --user enable --now webtop.service +systemctl --user enable webtop.service From 1299c39e81d9aa45309c6c14846bdd1989e9671c Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Tue, 22 Nov 2022 13:00:50 +0100 Subject: [PATCH 05/10] configure-module: set public and davserver urls --- imageroot/actions/configure-module/20config | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/imageroot/actions/configure-module/20config b/imageroot/actions/configure-module/20config index faf1c14e..86cca632 100755 --- a/imageroot/actions/configure-module/20config +++ b/imageroot/actions/configure-module/20config @@ -30,6 +30,7 @@ import json import sys import os import agent +import tempfile # Try to parse the stdin as JSON. # If parsing fails, output everything to stderr @@ -42,6 +43,8 @@ if not agent_id: # Connect to redis r = agent.redis_connect(privileged=True).pipeline() +restart_webapp = False + if data.get("hostname") is not None: if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) @@ -60,3 +63,26 @@ if data.get("hostname") is not None: ) # Check if traefik configuration has been successfull agent.assert_exp(response['exit_code'] == 0) + + public_url = 'https://' + data["hostname"] + '/webtop' + dav_url = 'https://' + data["hostname"] + '/webtop-dav/server.php' + + tmp_sql_file = tempfile.NamedTemporaryFile() + + tmp_sql_file.write(b"DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'public.url';\n") + tmp_sql_file.write(b"INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'public.url', \'" + public_url.encode() + b"\');\n") + + tmp_sql_file.write(b"DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'davserver.url';\n") + tmp_sql_file.write(b"INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'davserver.url',\'" + dav_url.encode() + b"\');\n") + + tmp_sql_file.flush() + + os.system(f"podman cp {tmp_sql_file.name} postgres:/tmp/settings.sql") + os.system('podman exec postgres sh -c "psql -U postgres webtop5 < /tmp/settings.sql > /dev/null"') + + + agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) + restart_webapp = True + +if restart_webapp: + os.system("systemctl --user restart webapp") From 56ffcb115ab03e6126457e12a0d43187fb5d4ef8 Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Wed, 23 Nov 2022 16:40:01 +0100 Subject: [PATCH 06/10] configure-module: wait for postgres to be ready --- .../actions/configure-module/10start_service | 20 ++++++++++++++++++- .../actions/configure-module/80enable_service | 2 +- imageroot/systemd/user/postgres.service | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/imageroot/actions/configure-module/10start_service b/imageroot/actions/configure-module/10start_service index 00850cc2..439a11a0 100755 --- a/imageroot/actions/configure-module/10start_service +++ b/imageroot/actions/configure-module/10start_service @@ -19,5 +19,23 @@ # You should have received a copy of the GNU General Public License # along with NethServer. If not, see COPYING. # +# Redirect any output to the journal (stderr) -systemctl --user start webtop +set -e + +exec 1>&2 + +systemctl --user start postgres + +podman exec -i postgres sh -s <<'EOF' +query="SELECT EXISTS ( SELECT * FROM pg_tables WHERE schemaname = 'core' AND tablename = 'settings');" +psql -q -U postgres webtop5 -tA -c "$query" 2> /dev/null | grep -q t +db_check=$? +c=10 +while [ "$db_check" -ne 0 -o $c -eq 0 ]; do + sleep 1s + psql -q -U postgres webtop5 -tA -c "$query" 2> /dev/null | grep -q t + db_check=$? + c=$(expr $c - 1 ) +done +EOF diff --git a/imageroot/actions/configure-module/80enable_service b/imageroot/actions/configure-module/80enable_service index 476c05cb..eafe05d1 100755 --- a/imageroot/actions/configure-module/80enable_service +++ b/imageroot/actions/configure-module/80enable_service @@ -22,4 +22,4 @@ # If the control reaches this step, the service can be enabled and started -systemctl --user enable webtop.service +systemctl --user enable --now webtop.service diff --git a/imageroot/systemd/user/postgres.service b/imageroot/systemd/user/postgres.service index 5d2eb2af..6da6c95c 100644 --- a/imageroot/systemd/user/postgres.service +++ b/imageroot/systemd/user/postgres.service @@ -5,6 +5,8 @@ [Unit] Description=postgres server PartOf=webtop.service +Requires=webtop.service +After=webtop.service [Service] Environment=PODMAN_SYSTEMD_UNIT=%n From 3be6ed9b36afe97c94adaeb3ed2a2ad08ad8551b Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Thu, 24 Nov 2022 10:13:30 +0100 Subject: [PATCH 07/10] configure-module: make field `hostname` required --- imageroot/actions/configure-module/20config | 36 +++++++++---------- .../configure-module/validate-input.json | 1 + 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/imageroot/actions/configure-module/20config b/imageroot/actions/configure-module/20config index 86cca632..d24975ce 100755 --- a/imageroot/actions/configure-module/20config +++ b/imageroot/actions/configure-module/20config @@ -45,24 +45,23 @@ r = agent.redis_connect(privileged=True).pipeline() restart_webapp = False -if data.get("hostname") is not None: - if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): - agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) - - # Configure Traefik to route WebTop's host requests to the webtop module - response = agent.tasks.run( - agent_id=agent.resolve_agent_id('traefik@node'), - action='set-route', - data={ - 'instance': os.environ['MODULE_ID'], - 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], - 'http2https': True, - 'lets_encrypt': False, - 'host': data['hostname'], - }, - ) - # Check if traefik configuration has been successfull - agent.assert_exp(response['exit_code'] == 0) + +# Configure Traefik to route WebTop's host requests to the webtop module +response = agent.tasks.run( + agent_id=agent.resolve_agent_id('traefik@node'), + action='set-route', + data={ + 'instance': os.environ['MODULE_ID'], + 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], + 'http2https': True, + 'lets_encrypt': False, + 'host': data["hostname"], + }, +) +# Check if traefik configuration has been successfull +agent.assert_exp(response['exit_code'] == 0) + +if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): public_url = 'https://' + data["hostname"] + '/webtop' dav_url = 'https://' + data["hostname"] + '/webtop-dav/server.php' @@ -80,7 +79,6 @@ if data.get("hostname") is not None: os.system(f"podman cp {tmp_sql_file.name} postgres:/tmp/settings.sql") os.system('podman exec postgres sh -c "psql -U postgres webtop5 < /tmp/settings.sql > /dev/null"') - agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) restart_webapp = True diff --git a/imageroot/actions/configure-module/validate-input.json b/imageroot/actions/configure-module/validate-input.json index 4b9f6576..0496c538 100644 --- a/imageroot/actions/configure-module/validate-input.json +++ b/imageroot/actions/configure-module/validate-input.json @@ -9,6 +9,7 @@ } ], "type": "object", + "required": ["hostname"], "properties": { "hostname": { "type": "string", From bdbcd4878c4e73a228a48aff0ed471a6d866b1e1 Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Thu, 24 Nov 2022 10:38:44 +0100 Subject: [PATCH 08/10] configure-module: add https certificate config --- imageroot/actions/configure-module/20config | 7 ++++++- imageroot/actions/configure-module/validate-input.json | 8 ++++++++ imageroot/actions/create-module/10env | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/imageroot/actions/configure-module/20config b/imageroot/actions/configure-module/20config index d24975ce..e5a3abce 100755 --- a/imageroot/actions/configure-module/20config +++ b/imageroot/actions/configure-module/20config @@ -45,6 +45,11 @@ r = agent.redis_connect(privileged=True).pipeline() restart_webapp = False +webtop_request_https_certificate = os.environ["WEBTOP_REQUEST_HTTPS_CERTIFICATE"].lower() in ('true', '1', 't') +if data.get("request_https_certificate") is not None: + if data.get("request_https_certificate") != webtop_request_https_certificate: + webtop_request_https_certificate = data["request_https_certificate"] + agent.set_env("WEBTOP_REQUEST_HTTPS_CERTIFICATE", data["request_https_certificate"]) # Configure Traefik to route WebTop's host requests to the webtop module response = agent.tasks.run( @@ -54,7 +59,7 @@ response = agent.tasks.run( 'instance': os.environ['MODULE_ID'], 'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"], 'http2https': True, - 'lets_encrypt': False, + 'lets_encrypt': webtop_request_https_certificate, 'host': data["hostname"], }, ) diff --git a/imageroot/actions/configure-module/validate-input.json b/imageroot/actions/configure-module/validate-input.json index 0496c538..4948358a 100644 --- a/imageroot/actions/configure-module/validate-input.json +++ b/imageroot/actions/configure-module/validate-input.json @@ -6,6 +6,10 @@ "examples": [ { "hostname": "example.com" + }, + { + "hostname": "example.com", + "request_https_certificate": true } ], "type": "object", @@ -18,6 +22,10 @@ "examples": [ "example.com" ] + }, + "request_https_certificate": { + "type": "boolean", + "title": "Request a valid HTTPS certificate" } } } diff --git a/imageroot/actions/create-module/10env b/imageroot/actions/create-module/10env index 06b17484..cc979816 100755 --- a/imageroot/actions/create-module/10env +++ b/imageroot/actions/create-module/10env @@ -25,6 +25,7 @@ exec 1>&2 # Send any output to stderr, to not alter the action response protocol cat >&${AGENT_COMFD} < Date: Fri, 25 Nov 2022 18:08:39 +0100 Subject: [PATCH 09/10] configure-module: use a pipe to send SQL commands Instead of creating/copying a tempfile, psql will be forked and the SQL commands will be sent to it through a pipe. --- imageroot/actions/configure-module/20config | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/imageroot/actions/configure-module/20config b/imageroot/actions/configure-module/20config index e5a3abce..74a9faee 100755 --- a/imageroot/actions/configure-module/20config +++ b/imageroot/actions/configure-module/20config @@ -30,7 +30,7 @@ import json import sys import os import agent -import tempfile +import subprocess # Try to parse the stdin as JSON. # If parsing fails, output everything to stderr @@ -71,18 +71,14 @@ if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): public_url = 'https://' + data["hostname"] + '/webtop' dav_url = 'https://' + data["hostname"] + '/webtop-dav/server.php' - tmp_sql_file = tempfile.NamedTemporaryFile() + with subprocess.Popen(['podman', 'exec', '-i', 'postgres', 'psql', '-U', 'postgres', 'webtop5'], stdin=subprocess.PIPE, text=True) as psql: + print("DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'public.url';\n", file=psql.stdin) + print("INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'public.url', \'" + public_url + "\');\n", file=psql.stdin) - tmp_sql_file.write(b"DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'public.url';\n") - tmp_sql_file.write(b"INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'public.url', \'" + public_url.encode() + b"\');\n") + print("DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'davserver.url';\n", file=psql.stdin) + print("INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'davserver.url',\'" + dav_url + "\');\n", file=psql.stdin) - tmp_sql_file.write(b"DELETE FROM \"core\".\"settings\" WHERE service_id = 'com.sonicle.webtop.core' and key = 'davserver.url';\n") - tmp_sql_file.write(b"INSERT INTO \"core\".\"settings\" (\"service_id\", \"key\", \"value\") VALUES ('com.sonicle.webtop.core', 'davserver.url',\'" + dav_url.encode() + b"\');\n") - - tmp_sql_file.flush() - - os.system(f"podman cp {tmp_sql_file.name} postgres:/tmp/settings.sql") - os.system('podman exec postgres sh -c "psql -U postgres webtop5 < /tmp/settings.sql > /dev/null"') + agent.assert_exp(psql.returncode == 0) # check the command is succesfull agent.set_env("WEBTOP_HOSTNAME", data["hostname"]) restart_webapp = True From b4aa02bb8f200e60614265428ba1770c566a0f4a Mon Sep 17 00:00:00 2001 From: Matteo Valentini Date: Mon, 28 Nov 2022 10:35:37 +0100 Subject: [PATCH 10/10] configure-module: use agent lib to restart webapp --- imageroot/actions/configure-module/20config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imageroot/actions/configure-module/20config b/imageroot/actions/configure-module/20config index 74a9faee..14a4d9f2 100755 --- a/imageroot/actions/configure-module/20config +++ b/imageroot/actions/configure-module/20config @@ -84,4 +84,4 @@ if data["hostname"] != os.getenv("WEBTOP_HOSTNAME"): restart_webapp = True if restart_webapp: - os.system("systemctl --user restart webapp") + agent.run_helper("systemctl", "--user", "restart", "webapp").check_returncode()