bugfixes and cleanup from kenyaemr

- fix monitor script
- fix to allow docker build-image script to run from outside folder
- split instance configuration out of start script
This commit is contained in:
2024-03-14 16:27:56 -07:00
parent 50cb23a4c7
commit 6c59b1ab76
5 changed files with 68 additions and 20 deletions
+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CONF_FILE=${LOCATION}/instances.conf
INSTANCES_DIR=${LOCATION}/instances
COMPOSE_FILE=${LOCATION}/docker-compose.yml
SETUP_FILE=${LOCATION}/setup
ENV_TEMPLATE=${LOCATION}/template.env
VERSION_FILE=${LOCATION}/version
version=$(head -n 1 ${VERSION_FILE} 2>/dev/null)
if [ $? -ne 0 ];then
version="unknown version"
fi
echo "Configuring Kenya EMR: $version"
if [ ! -f "${CONF_FILE}" ]; then
echo "missing conf file: ${CONF_FILE}"
exit 1
fi
echo "processing config file: ${CONF_FILE}"
# load instance names and port numbers from conf file
instances=($(sed -n "s/INSTANCES=//p" ${CONF_FILE}))
db_ports=($(sed -n "s/DB_PORTS=//p" ${CONF_FILE}))
http_ports=($(sed -n "s/HTTP_PORTS=//p" ${CONF_FILE}))
https_ports=($(sed -n "s/HTTPS_PORTS=//p" ${CONF_FILE}))
for ((i=0;i<${#instances[@]};i++)); do
# prepare directory and config files for instance
instance=$(echo ${instances[$i]} | tr -d '"')
db_port=$(echo ${db_ports[$i]} | tr -d '"')
http_port=$(echo ${http_ports[$i]} | tr -d '"')
https_port=$(echo ${https_ports[$i]} | tr -d '"')
echo
echo "configuring instance $((i+1)) / ${#instances[@]}"
echo " name: ${instance}"
echo " db_port: ${db_port}"
echo " http_port: ${http_port}"
echo " https_port: ${https_port}"
mkdir -p ${INSTANCES_DIR}/${instance}/data
sed -e "s/{{INSTANCE_NAME}}/${instance}/g" -e "s/{{INSTANCE_DB_PORT}}/${db_port}/g" -e "s/{{INSTANCE_HTTP_PORT}}/${http_port}/g" -e "s/{{INSTANCE_HTTPS_PORT}}/${https_port}/g" ${ENV_TEMPLATE} > ${INSTANCES_DIR}/${instance}/.env
cp ${COMPOSE_FILE} ${INSTANCES_DIR}/${instance}/
cp ${SETUP_FILE} ${INSTANCES_DIR}/${instance}/
done
echo "done."
@@ -9,6 +9,9 @@ function cleanup {
trap cleanup EXIT
# configure instances
${LOCATION}/configure
# start all instances
${LOCATION}/start
@@ -15,7 +15,7 @@ for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); d
else
echo "no services found"
fi
fi
done
popd > /dev/null
done
echo "done."
echo "done."
@@ -4,8 +4,6 @@ LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CONF_FILE=${LOCATION}/instances.conf
INSTANCES_DIR=${LOCATION}/instances
COMPOSE_FILE=${LOCATION}/docker-compose.yml
ENV_TEMPLATE=${LOCATION}/template.env
VERSION_FILE=${LOCATION}/version
version=$(head -n 1 ${VERSION_FILE} 2>/dev/null)
@@ -23,24 +21,21 @@ echo "processing config file: ${CONF_FILE}"
# load instance names and port numbers from conf file
instances=($(sed -n "s/INSTANCES=//p" ${CONF_FILE}))
ports=($(sed -n "s/APP_PORTS=//p" ${CONF_FILE}))
for ((i=0;i<${#instances[@]};i++)); do
# prepare directory and config files for instance
instance=$(echo ${instances[$i]} | tr -d '"')
port=$(echo ${ports[$i]} | tr -d '"')
echo
echo "configuring instance $((i+1)) / ${#instances[@]}"
echo " name: ${instance}"
echo " port: ${port}"
mkdir -p ${INSTANCES_DIR}/${instance}/data
sed -e "s/{{INSTANCE_NAME}}/${instance}/g" -e "s/{{INSTANCE_PORT}}/${port}/g" ${ENV_TEMPLATE} > ${INSTANCES_DIR}/${instance}/.env
cp ${COMPOSE_FILE} ${INSTANCES_DIR}/${instance}/
echo "starting instance $((i+1)) / ${#instances[@]}"
# start app
pushd ${INSTANCES_DIR}/${instance} > /dev/null
docker compose up -d --force-recreate
# setup instance
${INSTANCES_DIR}/${instance}/setup
# start app
docker compose up -d --force-recreate
popd > /dev/null
done
echo "done."
echo "done."