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

Merge pull request #4 Fix redis configuration

Fix redis configuration
This commit is contained in:
Jean-Baptiste 2018-05-12 23:58:11 +02:00 committed by GitHub
commit 9b30b38567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 16 deletions

View file

@ -72,7 +72,7 @@ DATABASE_URL=postgresql://__DBUSER__:__DBPWD__@:5432/__DBNAME__
# CACHE_URL=redis://<host>:<port>/<database>
# CACHE_URL=redis://localhost:6379/0
# Use the next one if you followed Debian installation guide
CACHE_URL=redis://127.0.0.1:6379/__APP__
CACHE_URL=redis://127.0.0.1:6379/__REDIS_DB__
# Where media files (such as album covers or audio tracks) should be stored
# on your system?

View file

@ -1,21 +1,43 @@
#!/bin/bash
# Remove the dedicated uwsgi ini file
#=================================================
#
# usage: ynh_remove_systemd_config
ynh_remove_uwsgi_service () {
finaluwsgiini="/etc/uwsgi/apps-available/$app.ini"
if [ -e "$finaluwsgiini" ]; then
systemctl stop "uwsgi-app@$app.socket"
systemctl disable "uwsgi-app@$app.socket"
yunohost service remove "uwsgi-app@$app.socket"
# Redis HELPERS
#
# Point of contact : Jean-Baptiste Holcroft <jean-baptiste@holcroft.fr>
#=================================================
ynh_secure_remove "$finaluwsgiini"
ynh_secure_remove "/var/run/uwsgi/$app.socket"
ynh_secure_remove "/var/log/uwsgi/app/$app"
fi
# 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
result=$(redis-cli INFO keyspace)
db=0
# default Debian setting is 15 databases
for i in $(seq 0 15)
do
if ! echo "$result" | grep -q "db$i"
then
db=$i
break 1
fi
done
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

@ -160,10 +160,12 @@ configfile="$final_path/config/.env"
cp ../conf/env.prod "$configfile"
key=$(ynh_string_random)
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set "$app" key "$key"
ynh_app_setting_set "$app" redis_db "$redis_db"
ynh_replace_string "__APP__" "$app" "$configfile"
ynh_replace_string "__REDIS_DB__" "$redis_db" "$configfile"
ynh_replace_string "__PORT__" "$port" "$configfile"
ynh_replace_string "__DOMAIN__" "$domain" "$configfile"
ynh_replace_string "__DBUSER__" "$db_name" "$configfile"

View file

@ -20,6 +20,7 @@ db_name=$(ynh_app_setting_get $app db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
redis_db=$(ynh_app_setting_get $app redis_db)
#=================================================
# STANDARD REMOVE
@ -42,6 +43,13 @@ ynh_secure_remove "/etc/systemd/system/$app.target"
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db "$db_name" "$app"
#=================================================
# REMOVE THE Redis DATABASE
#=================================================
# Remove a database if it exists, along with the associated user
ynh_redis_remove_db "$redis_db"
#=================================================
# REMOVE DEPENDENCIES
#=================================================

View file

@ -23,12 +23,17 @@ db_name=$(ynh_app_setting_get "$app" db_name)
db_user=$db_name
port=$(ynh_app_setting_get "$app" port)
db_pwd=$(ynh_app_setting_get "$app" psqlpwd)
redis_db=$(ynh_app_setting_get "$app" redis_db)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Not yet needed
# If redis_db doesn't exist, create it
if [ -z "$redis_db" ]; then
redis_db=0
ynh_app_setting_set "$app" redis_db "$redis_db"
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
@ -134,7 +139,7 @@ key=$(ynh_string_random)
ynh_app_setting_set "$app" key "$key"
ynh_replace_string "__APP__" "$app" "$configfile"
ynh_replace_string "__REDIS_DB__" "$redis_db" "$configfile"
ynh_replace_string "__PORT__" "$port" "$configfile"
ynh_replace_string "__DOMAIN__" "$domain" "$configfile"
ynh_replace_string "__DBUSER__" "$db_name" "$configfile"