mirror of
https://github.com/YunoHost-Apps/castopod_ynh.git
synced 2024-09-03 18:16:14 +02:00
Add redis helper
This commit is contained in:
parent
da4b1a3964
commit
5160a5ac3e
5 changed files with 57 additions and 3 deletions
|
@ -34,4 +34,4 @@ cache.handler="redis"
|
||||||
cache.redis.host="127.0.0.1"
|
cache.redis.host="127.0.0.1"
|
||||||
cache.redis.password=null
|
cache.redis.password=null
|
||||||
cache.redis.port=6379
|
cache.redis.port=6379
|
||||||
cache.redis.database=__REDIS_NUMBER__
|
cache.redis.database=__REDIS_DB__
|
||||||
|
|
|
@ -21,3 +21,45 @@ pkg_dependencies="redis-server redis-tools"
|
||||||
#=================================================
|
#=================================================
|
||||||
# FUTURE OFFICIAL HELPERS
|
# 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
|
||||||
|
}
|
||||||
|
|
|
@ -111,7 +111,11 @@ phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring Castopod..." --weight=1
|
ynh_script_progression --message="Configuring Castopod..." --weight=1
|
||||||
|
|
||||||
redis_number=$(( $YNH_APP_INSTANCE_NUMBER - 1 ))
|
# Configure redis
|
||||||
|
redis_db=$(ynh_redis_get_free_db)
|
||||||
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
||||||
|
|
||||||
|
#redis_number=$(( $YNH_APP_INSTANCE_NUMBER - 1 ))
|
||||||
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
|
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
|
||||||
chmod 600 $final_path/.env
|
chmod 600 $final_path/.env
|
||||||
chown $app:www-data "$final_path/.env"
|
chown $app:www-data "$final_path/.env"
|
||||||
|
|
|
@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
db_user=$db_name
|
db_user=$db_name
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE THE MYSQL DATABASE
|
# REMOVE THE MYSQL DATABASE
|
||||||
|
@ -29,6 +30,13 @@ ynh_script_progression --message="Removing the MySQL database..." --weight=1
|
||||||
# Remove a database if it exists, along with the associated user
|
# Remove a database if it exists, along with the associated user
|
||||||
ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
|
ynh_mysql_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
|
# REMOVE DEPENDENCIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -21,6 +21,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||||
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||||
phpversion=$YNH_PHP_VERSION
|
phpversion=$YNH_PHP_VERSION
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -121,7 +122,6 @@ ynh_add_fpm_config --package="$extra_php_dependencies"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring Castopod..." --weight=1
|
ynh_script_progression --message="Configuring Castopod..." --weight=1
|
||||||
|
|
||||||
redis_number=$(( $YNH_APP_INSTANCE_NUMBER - 1 ))
|
|
||||||
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
|
ynh_add_config --template="../conf/.env.example" --destination="$final_path/.env"
|
||||||
chmod 600 $final_path/.env
|
chmod 600 $final_path/.env
|
||||||
chown $app:www-data "$final_path/.env"
|
chown $app:www-data "$final_path/.env"
|
||||||
|
|
Loading…
Add table
Reference in a new issue