From 7a6a94f10a86ad60434193664ec862cc785b0c70 Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 23 Oct 2024 10:38:51 +0400 Subject: [PATCH] redis multiple databases --- recipes/discourse/crud.sh | 14 +++++++++++++- templates/apps/discourse/forum.yml.j2 | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/recipes/discourse/crud.sh b/recipes/discourse/crud.sh index 0c0fb71..e05b926 100755 --- a/recipes/discourse/crud.sh +++ b/recipes/discourse/crud.sh @@ -31,8 +31,20 @@ function _create() { admin_password=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.password) redis_password=$(load_yaml_from_expanded credential.redis) + redis_host=$(lxc list ct1 -c4 -f csv | cut -d' ' -f1) + + echo -n "count redis databases..." + redis_database=$(lxc exec ct1 -- bash -c "redis-cli -h $redis_host -a $redis_password INFO keyspace | tail -n1 | grep db | cut -d: -f1") + redis_database=${redis_database#db} + if [[ "$redis_database" =~ ^[0-9]+$ ]]; then + redis_database=$((redis_database + 1)) + else + redis_database=0 + fi + PREFIX='' echo $redis_database + mkdir -p "$MIAOU_CONFIGDIR/apps/discourse" - APP_REDIS_PASSWORD=$redis_password APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null + APP_REDIS_DB=$redis_database APP_REDIS_PASSWORD=$redis_password APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null echo "creating templates ... OK" echo "copying files to container <$container> ... " diff --git a/templates/apps/discourse/forum.yml.j2 b/templates/apps/discourse/forum.yml.j2 index 22c8a5e..cc4b689 100644 --- a/templates/apps/discourse/forum.yml.j2 +++ b/templates/apps/discourse/forum.yml.j2 @@ -37,6 +37,7 @@ env: DISCOURSE_REDIS_HOST: ct1.lxd DISCOURSE_REDIS_PASSWORD: {{ env.APP_REDIS_PASSWORD }} + DISCOURSE_REDIS_DB: {{ env.APP_REDIS_DB }} volumes: - volume: