mirror of
https://github.com/YunoHost-Apps/fittrackee_ynh.git
synced 2024-09-03 18:36:16 +02:00
prepare mails (add redis)
This commit is contained in:
parent
aacd794144
commit
1159bd34a0
6 changed files with 67 additions and 4 deletions
|
@ -17,7 +17,7 @@ DATABASE_URL=postgresql://__DB_USER__:__DB_PWD__@:5432/__DB_NAME__
|
||||||
# DATABASE_DISABLE_POOLING=
|
# DATABASE_DISABLE_POOLING=
|
||||||
|
|
||||||
# Redis (required for API rate limits and email sending)
|
# Redis (required for API rate limits and email sending)
|
||||||
REDIS_URL=redis://
|
REDIS_URL=redis://127.0.0.1:6379/__REDIS_DB__
|
||||||
|
|
||||||
# API rate limits
|
# API rate limits
|
||||||
# API_RATE_LIMITS="300 per 5 minutes"
|
# API_RATE_LIMITS="300 per 5 minutes"
|
||||||
|
|
|
@ -14,6 +14,44 @@ fittrackee_version="0.7.23"
|
||||||
# EXPERIMENTAL HELPERS
|
# EXPERIMENTAL 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
|
# FUTURE OFFICIAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -36,10 +36,10 @@ ynh_change_url_nginx_config
|
||||||
#=================================================
|
#=================================================
|
||||||
# MODIFY THE CONFIG FILE
|
# MODIFY THE CONFIG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
#ynh_script_progression --message="Modifying a config file..." --weight=1
|
ynh_script_progression --message="Modifying a config file..." --weight=1
|
||||||
|
|
||||||
#domain=$new_domain
|
domain=$new_domain
|
||||||
#ynh_add_config --template="../conf/env.production" --destination="$install_dir/config/.env"
|
ynh_add_config --template="../conf/env.production" --destination="$install_dir/config/.env"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SYSTEMD SERVICE
|
||||||
|
|
|
@ -30,6 +30,11 @@ chown -R $app:www-data /var/log/$app/
|
||||||
# CONFIGURE THE INSTALL SCRIPT
|
# CONFIGURE THE INSTALL SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
# Configure redis
|
||||||
|
redis_db=$(ynh_redis_get_free_db)
|
||||||
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
||||||
|
|
||||||
|
|
||||||
# key for the .env __KEY__
|
# key for the .env __KEY__
|
||||||
key=$(ynh_string_random --length=45 | base64)
|
key=$(ynh_string_random --length=45 | base64)
|
||||||
ynh_app_setting_set --app=$app --key=key --value=$key
|
ynh_app_setting_set --app=$app --key=key --value=$key
|
||||||
|
|
|
@ -9,6 +9,12 @@
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="Loading installation settings..."
|
||||||
|
|
||||||
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD REMOVE
|
# STANDARD REMOVE
|
||||||
|
@ -47,6 +53,9 @@ ynh_remove_logrotate
|
||||||
# Remove the log files
|
# Remove the log files
|
||||||
ynh_secure_remove --file="/var/log/$app"
|
ynh_secure_remove --file="/var/log/$app"
|
||||||
|
|
||||||
|
# Remove the redis database
|
||||||
|
ynh_redis_remove_db "$redis_db"
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
|
source ynh_redis
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -22,6 +23,16 @@ admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
|
||||||
|
|
||||||
upgrade_type=$(ynh_check_app_version_changed)
|
upgrade_type=$(ynh_check_app_version_changed)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# STANDARD UPGRADE STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue