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

Add redis

This commit is contained in:
ericgaspar 2021-11-16 23:11:44 +01:00
parent b10e7fa2c8
commit 44018fa7d5
4 changed files with 54 additions and 1 deletions

View file

@ -80,7 +80,7 @@ redis:
port: 6379
#pass: example-pass
#prefix: example-prefix
#db: 1
db: __REDIS_DB__
# ┌─────────────────────────────┐
#───┘ Elasticsearch configuration └─────────────────────────────

View file

@ -20,3 +20,45 @@ pkg_dependencies="build-essential ffmpeg postgresql postgresql-contrib"
#=================================================
# 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

@ -126,6 +126,10 @@ ynh_add_systemd_config
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
# Configure redis
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
ynh_add_config --template="../conf/default.yml" --destination="$final_path/.config/default.yml"
#=================================================

View file

@ -51,6 +51,13 @@ ynh_script_progression --message="Removing the PostgreSQL database..." --weight=
# 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..." --weight=1
ynh_redis_remove_db "$redis_db"
#=================================================
# REMOVE DEPENDENCIES
#=================================================