From 6d7bae6b5b67002155e1ca9a0748880a8592e00e Mon Sep 17 00:00:00 2001 From: MOHANKUMAR T <31698165+mohan-13@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:47:13 +0530 Subject: [PATCH] BAH-3380 | Add script to update openmrs and elis host and port for atomfeed sync (#95) --- package/docker/Dockerfile | 7 +++++++ package/docker/scripts/start.sh | 3 +++ .../docker/scripts/update_openmrs_host_port.sh | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 package/docker/scripts/update_openmrs_host_port.sh diff --git a/package/docker/Dockerfile b/package/docker/Dockerfile index 9faef477..94aaa523 100644 --- a/package/docker/Dockerfile +++ b/package/docker/Dockerfile @@ -9,6 +9,10 @@ ENV DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=8002,server=y,suspend # Used by envsubst command for replacing environment values at runtime RUN yum install -y gettext +RUN yum install -y nc +RUN yum install -y postgresql + +ADD https://raw.githubusercontent.com/eficode/wait-for/v2.2.3/wait-for wait-for.sh ADD https://repo.mybahmni.org/packages/build/bahmni-embedded-tomcat-8.0.42.jar /opt/bahmni-erp-connect/lib/bahmni-erp-connect.jar COPY openerp-atomfeed-service/target/openerp-atomfeed-service.war /etc/bahmni-erp-connect/openerp-atomfeed-service.war @@ -20,6 +24,9 @@ COPY package/resources/log4j2.properties ${WAR_DIRECTORY}/WEB-INF/classes/ COPY package/docker/templates/erp-atomfeed.properties.template /opt/bahmni-erp-connect/etc/erp-atomfeed.properties.template COPY package/docker/scripts/run-liquibase.sh /opt/bahmni-erp-connect/etc/run-liquibase.sh RUN chmod +x /opt/bahmni-erp-connect/etc/run-liquibase.sh +COPY package/docker/scripts/update_openmrs_host_port.sh update_openmrs_host_port.sh +RUN chmod +x update_openmrs_host_port.sh +RUN chmod +x wait-for.sh COPY package/docker/scripts/start.sh start.sh RUN chmod +x start.sh diff --git a/package/docker/scripts/start.sh b/package/docker/scripts/start.sh index 1f0cce88..eea24f60 100644 --- a/package/docker/scripts/start.sh +++ b/package/docker/scripts/start.sh @@ -1,8 +1,11 @@ #!/bin/sh set -e +echo "Waiting for ${ODOO_DB_SERVER}:5432 for 3600 seconds" +sh wait-for.sh --timeout=3600 ${ODOO_DB_SERVER}:5432 echo "[INFO] Substituting Environment Variables" envsubst < /opt/bahmni-erp-connect/etc/erp-atomfeed.properties.template > ${WAR_DIRECTORY}/WEB-INF/classes/erp-atomfeed.properties +./update_openmrs_host_port.sh echo "[INFO] Running Liquibase migrations" sh /opt/bahmni-erp-connect/etc/run-liquibase.sh echo "[INFO] Starting Application" diff --git a/package/docker/scripts/update_openmrs_host_port.sh b/package/docker/scripts/update_openmrs_host_port.sh new file mode 100644 index 00000000..445dfaeb --- /dev/null +++ b/package/docker/scripts/update_openmrs_host_port.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set +e + +run_sql() { + PGPASSWORD="${ODOO_DB_PASSWORD}" psql --host="${ODOO_DB_SERVER}" -U "${ODOO_DB_USERNAME}" -d odoo -t -c "$1" +} + +if [ $(run_sql "select count(*) from information_schema.tables where table_name='markers' and table_schema='public';") -gt 0 ] +then + echo "Updating OpenMRS Host Port in markers and failed_events table" + run_sql "UPDATE markers SET feed_uri_for_last_read_entry = regexp_replace(feed_uri_for_last_read_entry, 'http://.*/openmrs', 'http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs'),feed_uri = regexp_replace(feed_uri, 'http://.*/openmrs', 'http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs') where feed_uri ~ 'openmrs';" + run_sql "UPDATE failed_events SET feed_uri = regexp_replace(feed_uri, 'http://.*/openmrs', 'http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs') where feed_uri ~'openmrs';" + + echo "Updating OpenELIS Host Port in markers and failed_events table" + run_sql "UPDATE markers SET feed_uri_for_last_read_entry = regexp_replace(feed_uri_for_last_read_entry, 'http://.*/openelis', 'http://${OPENELIS_HOST}:${OPENELIS_PORT}/openelis'),feed_uri = regexp_replace(feed_uri, 'http://.*/openelis', 'http://${OPENELIS_HOST}:${OPENELIS_PORT}/openelis') where feed_uri ~ 'openelis';" + run_sql "UPDATE failed_events SET feed_uri = regexp_replace(feed_uri, 'http://.*/openelis', 'http://${OPENELIS_HOST}:${OPENELIS_PORT}/openelis') where feed_uri ~'openelis';" +fi