improve node gestion

This commit is contained in:
oiseauroch 2022-09-12 13:18:58 +02:00
parent abff1b3ce2
commit 8eaf3bf1b6
4 changed files with 53 additions and 8 deletions

View File

@ -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
#=================================================

View File

@ -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

View File

@ -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
#=================================================

View File

@ -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
#=================================================