Reimplement scripts to support multiple app instances

An additional config file `instances.conf` is added to define instance names and
port numbers. The existing `app.conf` was also modified to include an
`instances` field and to move node id and location under this new object. A
`.env` file is used to manage configuration for each instance.

Additional scripts are added: `start`, `stop`, `monitor` - see docs for
description. The main entry script is also modified such that it will run until
any service stops, then brings down the remaining services and exits.
This commit is contained in:
2024-03-08 12:29:37 -08:00
parent 407baf9727
commit 04cbf6b1af
10 changed files with 136 additions and 43 deletions
@@ -1,9 +1,9 @@
version: '3.9'
services:
streamline-emr:
image: streamline-emr:2.0
container_name: ${CONTAINER_NAME:-streamline-emr}
image: ${IMAGE:-streamline-emr:2.0}
container_name: ${CONTAINER_NAME}
volumes:
- "${DATA_DIR:-/var/signalytic/clientapps/streamline/streamline-emr/data}:/var/lib/mysql"
- "${DATA_DIR}:/var/lib/mysql"
ports:
- "${APP_PORT:-3000}:80"
- "${APP_PORT}:80"
@@ -1,17 +1,20 @@
#!/bin/bash
APPROOT="$(dirname "${BASH_SOURCE[0]}")"
LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "entering app root: $APPROOT"
cd $APPROOT
# start all instances
${LOCATION}/start
echo "creating data folder (if necessary)"
mkdir -p data
# wait for any service to stop
pids=()
for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do
pushd $(dirname $f) > /dev/null
docker compose wait streamline-emr &
pids+=($!)
popd > /dev/null
done
echo "waiting on processes: ${pids[@]}"
wait -n ${pids[@]} > /dev/null
echo "starting app"
docker compose up
echo "cleaning up"
docker compose down
echo "done."
# cleanup
${LOCATION}/stop
@@ -0,0 +1,19 @@
#!/bin/bash
LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do
pushd $(dirname $f) > /dev/null
status=$(docker compose ps --format '{"name":"{{.Names}}","created":"{{.CreatedAt}}","elapsed":"{{.RunningFor}}","state":"{{.State}}","status":"{{.Status}}"}')
popd > /dev/null
if [ "${status}" ]; then
echo $status
if command -v bgsystemlog &> /dev/null
then
bgsystemlog -j streamline_emr -m "'${status}'"
fi
else
echo "no services found"
fi
done
echo "done."
@@ -0,0 +1,41 @@
#!/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
ENV_TEMPLATE=${LOCATION}/template.env
echo "starting all instances"
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}))
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}/
# start app
pushd ${INSTANCES_DIR}/${instance} > /dev/null
docker compose up -d --force-recreate
popd > /dev/null
done
echo "done."
@@ -0,0 +1,11 @@
#!/bin/bash
LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "stopping all instances"
for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do
pushd $(dirname $f) > /dev/null
docker compose down
popd > /dev/null
done
echo "done."
@@ -1,22 +1,22 @@
{
"name": "Streamline EMR",
"database": {
"type": "mysql",
"version": "mariadb:15.1",
"name": "streamline",
"source": "streamline-emr",
"username": "",
"password": "",
"db_path": "/var/lib/mysql",
"logs_path": "/var/lib/mysql/logs",
"log_pattern": "bin.[0-9]*"
},
"blockgraph": {
"district": "",
"name": "",
"node": "",
"location": "",
"username": "",
"password": ""
"dbsync": {
"database": {
"type": "mysql",
"version": "8.0.23",
"name": "main",
"username": "",
"password": "",
"db_path": "/var/lib/mysql",
"logs_path": "/var/lib/mysql/logs",
"log_pattern": "binlog.[0-9]*"
},
"blockgraph": {
"district": "",
"name": "",
"username": "",
"password": ""
},
"instances": {}
}
}
}
@@ -0,0 +1,5 @@
COMPOSE_PROJECT_NAME={{INSTANCE_NAME}}
CONTAINER_NAME=streamline-emr-{{INSTANCE_NAME}}
DATA_DIR=/var/signalytic/clientapps/streamline/streamline-emr/instances/{{INSTANCE_NAME}}/data
APP_PORT={{INSTANCE_PORT}}
#IMAGE=streamline-emr:2.0
@@ -0,0 +1,2 @@
INSTANCES=
APP_PORTS=