diff --git a/imageroot/actions/configure-module/80start_services b/imageroot/actions/configure-module/80start_services index 5fffc00..6868d0f 100755 --- a/imageroot/actions/configure-module/80start_services +++ b/imageroot/actions/configure-module/80start_services @@ -14,3 +14,4 @@ exec 1>&2 touch smarthost.env systemctl --user enable --now erp-next.service +systemctl --user try-restart erp-next.service \ No newline at end of file diff --git a/imageroot/actions/restore-module/40restore_database b/imageroot/actions/restore-module/40restore_database new file mode 100755 index 0000000..25b78fe --- /dev/null +++ b/imageroot/actions/restore-module/40restore_database @@ -0,0 +1,41 @@ +#!/bin/bash + +# +# Copyright (C) 2022 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +set -e -o pipefail +exec 1>&2 # Redirect any output to the journal (stderr) + +# Prepare an initialization script that restores the dump file +mkdir -vp initdb.d +mv -v erpnext.sql initdb.d +#do the bash file to restore and exit once done +cat - >initdb.d/zz_erpnext_restore.sh <<'EOS' +# Print additional information: +mysql --version +# The script is sourced, override entrypoint args and exit: +set -- true +docker_temp_server_stop +exit 0 +EOS + +# once we exit we remove initdb.d +trap 'rm -rfv initdb.d/' EXIT + +# we start a container to initiate a database and load the dump +# at the end of erpnext_restore.sh the dump is loaded and +# we exit the container +podman run \ + --rm \ + --interactive \ + --network=none \ + --volume=./initdb.d:/docker-entrypoint-initdb.d:z \ + --volume mysql-data:/var/lib/mysql/:Z \ + --env MARIADB_ROOT_PASSWORD=Nethesis,1234 \ + --env MARIADB_DATABASE=erpnext \ + --env MARIADB_USER=erpnext \ + --env MARIADB_PASSWORD=erpnext \ + --replace --name=restore_db \ + ${MARIADB_IMAGE} \ No newline at end of file diff --git a/imageroot/actions/restore-module/50traefik b/imageroot/actions/restore-module/50traefik index e6a6fdd..25a0e53 100755 --- a/imageroot/actions/restore-module/50traefik +++ b/imageroot/actions/restore-module/50traefik @@ -14,8 +14,8 @@ request = json.load(sys.stdin) renv = request['environment'] configure_retval = agent.tasks.run(agent_id=os.environ['AGENT_ID'], action='configure-module', data={ - "lets_encrypt": renv["TRAEFIK_LETS_ENCRYPT"], + "lets_encrypt": renv["TRAEFIK_LETS_ENCRYPT"] == True, "host": renv["TRAEFIK_HOST"], - "http2https": renv["TRAEFIK_HTTP2HTTPS"], + "http2https": renv["TRAEFIK_HTTP2HTTPS"] == True, }) -agent.assert_exp(configure_retval['exit_code'] == 0, "The configure-module subtask failed!") +agent.assert_exp(configure_retval['exit_code'] == 0, "The configure-module subtask failed!") \ No newline at end of file diff --git a/imageroot/bin/module-cleanup-state b/imageroot/bin/module-cleanup-state new file mode 100755 index 0000000..dbbd4a4 --- /dev/null +++ b/imageroot/bin/module-cleanup-state @@ -0,0 +1,8 @@ +#!/bin/bash + +# +# Copyright (C) 2022 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +rm -vf erpnext.sql \ No newline at end of file diff --git a/imageroot/bin/module-dump-state b/imageroot/bin/module-dump-state new file mode 100755 index 0000000..84ffb12 --- /dev/null +++ b/imageroot/bin/module-dump-state @@ -0,0 +1,21 @@ +#!/bin/bash + +# +# Copyright (C) 2022 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +set -e + +if ! systemctl --user -q is-active erpnext.service; then + exit 0 +fi + +podman exec mariadb-app mysqldump \ + --databases erpnext \ + --default-character-set=utf8mb4 \ + --skip-dump-date \ + --ignore-table=mysql.event \ + --single-transaction \ + --quick \ + --add-drop-table > erpnext.sql \ No newline at end of file diff --git a/imageroot/systemd/user/erp-next-mariadb.service b/imageroot/systemd/user/erp-next-mariadb.service index c8cf335..9d6f94e 100644 --- a/imageroot/systemd/user/erp-next-mariadb.service +++ b/imageroot/systemd/user/erp-next-mariadb.service @@ -21,9 +21,9 @@ ExecStart=/usr/bin/podman run --conmon-pidfile %t/mariadb-app.pid \ --env-file=%S/state/environment \ --volume mysql-data:/var/lib/mysql/:Z \ --env MARIADB_ROOT_PASSWORD=Nethesis,1234 \ - --env MARIADB_DATABASE=erp-next \ - --env MARIADB_USER=erp-next \ - --env MARIADB_PASSWORD=erp-next \ + --env MARIADB_DATABASE=erpnext \ + --env MARIADB_USER=erpnext \ + --env MARIADB_PASSWORD=erpnext \ --env MARIADB_AUTO_UPGRADE=1 \ ${MARIADB_IMAGE} \ --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --skip-character-set-client-handshake