mirror of
https://github.com/YunoHost-Apps/nextcloud_ynh.git
synced 2024-09-03 19:55:57 +02:00
Configure redis to avoid db overlaps
This commit is contained in:
parent
2749fc801a
commit
7807979b07
4 changed files with 55 additions and 0 deletions
|
@ -86,6 +86,49 @@ ynh_smart_mktemp () {
|
|||
echo "$(mktemp --directory --tmpdir="$tmpdir")"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# 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 --message="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
|
||||
}
|
||||
|
||||
|
||||
#=================================================
|
||||
# FUTURE OFFICIAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -206,6 +206,9 @@ exec_occ config:import "$nc_conf"
|
|||
# Then remove the config file
|
||||
ynh_secure_remove --file="$nc_conf"
|
||||
|
||||
redis_db=$(ynh_redis_get_free_db)
|
||||
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
||||
|
||||
# Load the additional config file (used also for upgrade)
|
||||
nc_conf="$final_path/config.json"
|
||||
ynh_add_config --template="../conf/config.json" --destination="$nc_conf"
|
||||
|
|
|
@ -21,6 +21,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|||
db_user=$db_name
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
|
@ -40,6 +41,13 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=5
|
|||
# Remove a database if it exists, along with the associated user
|
||||
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE REDIS DATABASE
|
||||
#=================================================
|
||||
ynh_script_progression --message="Removing the redis database..."
|
||||
|
||||
ynh_redis_remove_db "$redis_db"
|
||||
|
||||
#=================================================
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
|
|
|
@ -27,6 +27,7 @@ user_home=$(ynh_app_setting_get --app=$app --key=user_home)
|
|||
maintenance_mode=$(ynh_app_setting_get --app=$app --key=maintenance_mode)
|
||||
fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint)
|
||||
fpm_usage=$(ynh_app_setting_get --app=$app --key=fpm_usage)
|
||||
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||
|
||||
#=================================================
|
||||
# CHECK VERSION
|
||||
|
|
Loading…
Add table
Reference in a new issue