Skip to content

Commit

Permalink
Implement database dump and restore, and start service
Browse files Browse the repository at this point in the history
  • Loading branch information
compgeniuses committed Jun 12, 2024
1 parent 2b21a7c commit 3323d86
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 6 deletions.
1 change: 1 addition & 0 deletions imageroot/actions/configure-module/80start_services
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ exec 1>&2
touch smarthost.env

systemctl --user enable --now erp-next.service
systemctl --user try-restart erp-next.service
41 changes: 41 additions & 0 deletions imageroot/actions/restore-module/40restore_database
Original file line number Diff line number Diff line change
@@ -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}
6 changes: 3 additions & 3 deletions imageroot/actions/restore-module/50traefik
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
8 changes: 8 additions & 0 deletions imageroot/bin/module-cleanup-state
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions imageroot/bin/module-dump-state
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions imageroot/systemd/user/erp-next-mariadb.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3323d86

Please sign in to comment.