diff --git a/scripts/_common.sh b/scripts/_common.sh index 45ec91e..f65835f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,3 +10,41 @@ current_hash=cc5b1c950be5b1b290ea76e3419057dffaeab797 #================================================= # PERSONAL 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 +} \ No newline at end of file diff --git a/scripts/remove b/scripts/remove index f311a1d..f8215fc 100644 --- a/scripts/remove +++ b/scripts/remove @@ -16,13 +16,19 @@ source /usr/share/yunohost/helpers ynh_script_progression --message="Removing system configurations related to $app..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_exec_warn_less yunohost service status $app-backend >/dev/null then - ynh_script_progression --message="Removing $app service integration..." - yunohost service remove $app + ynh_script_progression --message="Removing $app-backend service integration..." + yunohost service remove $app-backend + ynh_remove_systemd_config --service="$app-backend" fi -ynh_remove_systemd_config +if ynh_exec_warn_less yunohost service status $app-exporter >/dev/null +then + ynh_script_progression --message="Removing $app-exporter service integration..." + yunohost service remove $app-exporter + ynh_remove_systemd_config --service="$app-exporter" +fi ynh_remove_nginx_config @@ -32,6 +38,8 @@ ynh_remove_logrotate ynh_secure_remove --file="/var/log/$app" +ynh_redis_remove_db "$redis_db" + #================================================= # END OF SCRIPT #=================================================