1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/discourse_ynh.git synced 2024-09-03 18:26:18 +02:00

Use Redis helper to use an available database during installation

This commit is contained in:
Jimmy Monin 2018-07-01 10:06:14 +02:00
parent 569d8e9d74
commit 33d7d4b312
4 changed files with 58 additions and 0 deletions

View file

@ -651,3 +651,45 @@ ynh_maintenance_mode_OFF () {
systemctl reload nginx
}
#=================================================
# REDIS HELPERS
#=================================================
# get the first available redis database
#
# usage: ynh_redis_get_free_db
# | returns: the database number to use
ynh_redis_get_free_db() {
local result max db
result="$(redis-cli INFO keyspace)"
# get the num
max=$(cat /etc/redis/redis.conf | grep ^databases | grep -Eow "[0-9]+")
db=0
# default Debian setting is 15 databases
for i in $(seq 0 "$max")
do
if ! echo "$result" | grep -q "db$i"
then
db=$i
break 1
fi
db=-1
done
test "$db" -eq -1 && ynh_die "No available Redis databases..."
echo "$db"
}
# Create a master password and set up global settings
# Please always call this script in install and restore scripts
#
# usage: ynh_redis_remove_db database
# | arg: database - the database to erase
ynh_redis_remove_db() {
local db=$1
redis-cli -n "$db" flushall
}

View file

@ -148,6 +148,11 @@ ynh_replace_string "smtp_address =" "smtp_address = localhost" "$discourse_confi
ynh_replace_string "smtp_domain =" "smtp_domain = $domain" "$discourse_config_file"
ynh_replace_string "smtp_enable_start_tls = true" "smtp_enable_start_tls = false" "$discourse_config_file"
# Configure redis
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set "$app" redis_db "$redis_db"
ynh_replace_string "redis_db = 0" "redis_db = $redis_db" "$discourse_config_file"
# Calculate and store the config file checksum
ynh_store_file_checksum "$discourse_config_file"

View file

@ -18,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get $app final_path)
redis_db=$(ynh_app_setting_get $app redis_db)
#=================================================
# STANDARD REMOVE
@ -56,6 +57,12 @@ ynh_remove_ruby
ynh_psql_remove_db $db_name $db_name
#=================================================
# REMOVE THE REDIS DATABASE
#=================================================
ynh_redis_remove_db "$redis_db"
#=================================================
# REMOVE APP MAIN DIR
#=================================================

View file

@ -34,6 +34,7 @@ is_public=$(ynh_app_setting_get $app is_public)
admin=$(ynh_app_setting_get $app admin)
db_name=$(ynh_app_setting_get $app db_name)
db_pwd=$(ynh_app_setting_get $app db_pwd)
redis_db=$(ynh_app_setting_get $app redis_db)
# Check memory requirements
check_memory_requirements_upgrade
@ -130,6 +131,9 @@ if ! ynh_is_upstream_up_to_date ; then
ynh_replace_string "smtp_domain =" "smtp_domain = $domain" "$discourse_config_file"
ynh_replace_string "smtp_enable_start_tls = true" "smtp_enable_start_tls = false" "$discourse_config_file"
# Configure redis
ynh_replace_string "redis_db = 0" "redis_db = $redis_db" "$discourse_config_file"
# Calculate and store the config file checksum
ynh_store_file_checksum "$discourse_config_file"