From 8eaf3bf1b6b64fbb11dd7e60ecb3810953adaa39 Mon Sep 17 00:00:00 2001 From: oiseauroch Date: Mon, 12 Sep 2022 13:18:58 +0200 Subject: [PATCH] improve node gestion --- scripts/_common.sh | 22 ++++++++++++++++++++++ scripts/install | 11 ++++------- scripts/remove | 17 ++++++++++++++++- scripts/restore | 11 +++++++++++ 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 31e2ad3..0642659 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -42,6 +42,28 @@ install_garage () { fi } +init_garage() { +garage_command="$1" +node_id="$2" +weight="$3" +zone="$4" + +$garage_command layout assign $node_id -z $zone -c $weight -t $zone + +apply_layout "$garage_command" +} + +apply_layout() { + $garage_command=$1 + $garage_command -c garage.toml layout show 2>/dev/null | grep "--version" + if [ $? -eq 0 ] + then + layout_version=$($garage_command layout show 2>/dev/null | grep -Po -- "(?<=--version).*" | head -1 | xargs) + $garage_command layout apply --version $layout_version + else + return 1 + fi +} #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 6a2fdad..4b69c0a 100755 --- a/scripts/install +++ b/scripts/install @@ -368,15 +368,12 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Configuring garage..." --time --weight=1 -garage_command="$final_path/garage -c $final_path/garage.toml" +node_id=$($garage_command node id -q | cut -d '@' -f1) +ynh_app_setting_set --app=$app --key=node_id --value=node_id -garage_id=$($garage_command node id -q | cut -d '@' -f1) +garage_command="$garage_path/garage -c $garage_path/garage.toml" -$garage_command layout assign $garage_id -z $domain -c $weight -t $domain - -layout_version=$($garage_command layout show 2>/dev/null | grep -Po -- "(?<=--version).*" | head -1 | xargs) - -$garage_command layout apply --version $layout_version +init_garage "$garage_command" "$node_id" "$weight" "$domain" #================================================= # Send email to admin diff --git a/scripts/remove b/scripts/remove index 8f280b4..0f79639 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,4 +1,4 @@ -#!/bin/bash + #!/bin/bash #================================================= # GENERIC START @@ -24,6 +24,21 @@ port_web=$(ynh_app_setting_get --app=$app --key=port_web) datadir=$(ynh_app_setting_get --app=$app --key=datadir) bootstrap_peers=$(ynh_app_setting_get --app=$app --key=bootstrap_peers) nbd_index=$(ynh_app_setting_get --app=$app --key=nbd_index) +node_id=$(ynh_app_setting_get --app=$app --key=node_id) + + +#================================================= +# REMOVE NODE CONFIGURATION +#================================================= +$final_path/garage -c $final_path/garage.toml layout remove "$node_id" + +apply_layout "$final_path/garage -c $final_path/garage.toml " +if [ $? -ne 0 ] +then + ynh_die --message="unable to remove the node. Maybe the number of node staying alive is not enough" +fi + + #================================================= # STANDARD REMOVE #================================================= diff --git a/scripts/restore b/scripts/restore index 2d75231..b2cef2c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -32,6 +32,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) datadir=$(ynh_app_setting_get --app=$app --key=datadir) + #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= @@ -139,6 +140,16 @@ ynh_script_progression --message="Starting a systemd service..." --time --weight ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +#================================================= +# RECREATE CONFIGURATION +#================================================= +node_id=$(ynh_app_setting_get --app=$app --key=node_id) +weight=$(ynh_app_setting_get --app=$app --key=weight) + +garage_command="$garage_path/garage -c $garage_path/garage.toml" + +init_garage "$garage_command" "$node_id" "$weight" "$domain" + #================================================= # GENERIC FINALIZATION #=================================================