From a310de997423b855a929294b25078860ef10594d Mon Sep 17 00:00:00 2001 From: Tobias Ollive Date: Mon, 13 Dec 2021 15:19:39 +0100 Subject: [PATCH] use custom redis instance --- scripts/install | 17 +++++++++++++++++ scripts/remove | 4 ++++ scripts/restore | 10 +++++++++- scripts/upgrade | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 57a424f..042f824 100644 --- a/scripts/install +++ b/scripts/install @@ -59,6 +59,21 @@ ynh_script_progression --message="Finding an available port..." --weight=1 port=$(ynh_find_port --port=8080) ynh_app_setting_set --app=$app --key=port --value=$port +#================================================== +# CONFIGURE REDIS SERVICE +#================================================== + +ynh_install_app_dependencies redis-server redis-tools + +# Find an available port for redis +redis_port=$(ynh_find_port --port=8081) +ynh_app_setting_set --app=$app --key=redis_port --value=$redis_port + +ynh_add_config --template="redis.conf" --destination="$final_path/redis.conf" + +redis_service="redis-$app$" +ynh_add_systemd_config --service $redis_service --template scrumblr_redis + #================================================= # INSTALL NODEJS #================================================= @@ -66,6 +81,8 @@ ynh_script_progression --message="Installing dependencies..." --weight=5 ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version + + #================================================= # CREATE DEDICATED USER #================================================= diff --git a/scripts/remove b/scripts/remove index f45267e..691fc90 100644 --- a/scripts/remove +++ b/scripts/remove @@ -57,6 +57,10 @@ ynh_script_progression --message="Removing dependencies..." --weight=2 # Remove metapackage and its dependencies ynh_remove_nodejs +ynh_script_progression --message="Removing redis service" --weight=2 + +ynh_remove_systemd_config --service="redis-$app" + #================================================= # REMOVE APP MAIN DIR #================================================= diff --git a/scripts/restore b/scripts/restore index 6435899..663cf58 100644 --- a/scripts/restore +++ b/scripts/restore @@ -84,6 +84,14 @@ ynh_script_progression --message="Restoring the systemd configuration..." --weig ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet +#================================================= +# RESTORE redis service +#================================================= +ynh_script_progression --message="Restoring the redis configuration..." --weight=1 + +ynh_restore_file --origin_path="/etc/systemd/system/redis-$app.service" +systemctl enable "redis-$app.service" --quiet + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= @@ -103,7 +111,7 @@ yunohost service add $app --description="Software for notes" --log="/var/log/$ap #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Server running at port" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Server running at" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index b427e27..369bb94 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,6 +20,10 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) +if [ $(ynh_compare_current_package_version --comparison gt --version "0.2.0~ynh1" ] +then + redis_port=$(ynh_app_setting_get --app=$app --key=redis_port) +fi #================================================= # CHECK VERSION @@ -50,6 +54,10 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +if [ $(ynh_compare_current_package_version --comparison lt --version "0.2.0~ynh2" ] +then + ynh_systemd_action --service_name=redis-$app --action="stop" --log_path="/var/log/$app/redis-$app.log"ls +fi #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -100,6 +108,35 @@ then ynh_exec_warn_less $ynh_npm install popd fi + +#================================================= +# MIGRATE DATABASE +#================================================= +ynh_script_progression --message="migrating database..." --weight=1 + +if [ $(ynh_compare_current_package_version "0.2.0~ynh1" ] +then + pushd $final_path + redis-cli --rdb "redis-$app.rdb" + popd +fi + +#================================================= +# REDIS CONFIGURATION +#================================================= + +if [ $(ynh_compare_current_package_version --comparison lt --version "0.2.0~ynh2" ] +then +# Find an available port for redis + redis_port=$(ynh_find_port --port=8081) + ynh_app_setting_set --app=$app --key=redis_port --value=$redis_port +fi + +ynh_add_config --template="redis.conf" --destination="$final_path/redis.conf" + +redis_service="redis-$app$" +ynh_add_systemd_config --service $redis_service --template scrumblr_redis + #================================================= # NGINX CONFIGURATION #=================================================