1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/peertube_ynh.git synced 2024-09-03 19:56:29 +02:00

Set Redis db

This commit is contained in:
ericgaspar 2021-12-24 09:22:23 +01:00
parent 8985f3f1ef
commit 08f81f837f
5 changed files with 65 additions and 1 deletions

View file

@ -50,7 +50,7 @@ redis:
hostname: 'localhost'
port: 6379
auth: null
db: 0
db: __REDIS_DB__
# SMTP server to send emails
smtp:

View file

@ -20,3 +20,45 @@ NODEJS_VERSION=16
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
#=================================================
# 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
}

View file

@ -114,6 +114,13 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
#=================================================
# CONFIGURE REDIS
#=================================================
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================

View file

@ -27,6 +27,7 @@ admin=$(ynh_app_setting_get --app=$app --key=admin)
admin_email=$(ynh_user_get_info --username=$admin --key="mail")
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
path_url=$(ynh_app_setting_get --app=$app --key=path)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#=================================================
# STANDARD REMOVE
@ -57,6 +58,13 @@ ynh_script_progression --message="Removing the PostgreSQL database..."
# Remove a database if it exists, along with the associated user
ynh_psql_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 DEPENDENCIES
#=================================================

View file

@ -27,6 +27,7 @@ db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
admin=$(ynh_app_setting_get --app=$app --key=admin)
admin_email=$(ynh_user_get_info --username=$admin --key="mail")
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#=================================================
# CHECK VERSION
@ -79,6 +80,12 @@ if [ -z "$db_pwd" ]; then
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
fi
# If redis_db doesn't exist, create it
if [ -z "$redis_db" ]; then
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
fi
if [ -z "$datadir" ];
then
datadir="/home/yunohost.app/${app}/storage"