diff --git a/scripts/_common.sh b/scripts/_common.sh index cbadbf1..42a7e66 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -24,15 +24,16 @@ fi # PERSONAL HELPERS #================================================= +garage="$install_dir/garage -c $install_dir/garage.toml" + garage_connect() { - local command="$1" - local peer="$2" + local peer="$1" # connect to cluster - $command node connect "$peer" + $garage node connect "$peer" sleep 2 # wait until layout is updated local i=0 - until $command layout show 2>/dev/null | grep "${peer:0:15}"; do + until $garage layout show 2>/dev/null | grep "${peer:0:15}"; do i=$(( i + 1 )) if [ $i -gt 30 ] then @@ -43,24 +44,14 @@ garage_connect() { } -apply_layout() { - - garage_command=$1 - $garage_command layout show 2>/dev/null - if [ "$($garage_command layout show | grep 'This new layout cannot yet be applied')" ] +garage_layout_apply() { + $garage layout show 2>/dev/null + if [ "$($garage layout show | grep 'This new layout cannot yet be applied')" ] then ynh_print_warn --message="Unable to apply layout. No enough nodes" return 0 else - local layout_version=$($garage_command layout show 2>/dev/null | grep -Po -- "(?<=--version).*" | head -1 | xargs) - $garage_command layout apply --version $layout_version + local layout_version=$($garage layout show 2>/dev/null | grep -Po -- "(?<=--version).*" | head -1 | xargs) + $garage layout apply --version $layout_version fi } - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/config b/scripts/config index d007180..0b24848 100644 --- a/scripts/config +++ b/scripts/config @@ -10,13 +10,11 @@ source /usr/share/yunohost/helpers data_dir=$(ynh_app_setting_get $app data_dir) secret_node_id=$(ynh_app_setting_get $app data_dir) -if system_is_inside_container +if ! system_is_inside_container then nbd_index=$(cat $data_dir/nbd_index) fi -command="$install_dir/garage -c $install_dir/garage.toml" - set__weight() { if system_is_inside_container then @@ -39,29 +37,29 @@ set__weight() { systemctl start $app sleep 3 fi - $command layout assign $secret_node_id -c $weight 2>/dev/null - apply_layout "$command" + $garage layout assign $secret_node_id -c $weight 2>/dev/null + garage_layout_apply ynh_app_setting_set --app=$app --key=weight --value=$weight } set__bootstrap_peers() { - garage_connect "$command" "$bootstrap_peers" 2>/dev/null - apply_layout "$command" + garage_connect "$bootstrap_peers" 2>/dev/null + garage_layout_apply ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers } get__node() { cat << EOF ask: - en: "**Node Id** : $($command node id -q) \n + en: "**Node Id** : $($garage node id -q) \n *This id is a sensitive information and should not be shared with anyone else than other nodes of the cluster*" style: "info" EOF } get__status() { -status=$($command status 2> /dev/null | sed -E 's/([a-z0-9]{16})/\n**\1**/g') +status=$($garage status 2> /dev/null | sed -E 's/([a-z0-9]{16})/\n**\1**/g') cat << EOF ask: en: "**Current garage layout**: \n diff --git a/scripts/install b/scripts/install index 4465505..eeafaad 100755 --- a/scripts/install +++ b/scripts/install @@ -125,32 +125,30 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l #================================================= ynh_script_progression --message="Configuring garage..." --weight=1 -garage_command="$install_dir/garage -c $install_dir/garage.toml" - i=0 # sometimes server need some time to start -while [ -z "$($garage_command node id -q 2>/dev/null | cut -d '@' -f1)" ]; do +while [ -z "$($garage node id -q 2>/dev/null | cut -d '@' -f1)" ]; do i=$(( i + 1 )) - [ $i -le 30 ] || { $garage_command node id || true; ynh_die --message="unable to get node id"; } + [ $i -le 30 ] || { $garage node id || true; ynh_die --message="unable to get node id"; } sleep 1 done -secret_node_id=$($garage_command node id -q 2>/dev/null | cut -d '@' -f1) +secret_node_id=$($garage node id -q 2>/dev/null | cut -d '@' -f1) ynh_app_setting_set --app=$app --key=secret_node_id --value=$secret_node_id # define node -$garage_command layout assign $secret_node_id -z $domain -c $weight -t $domain +$garage layout assign $secret_node_id -z $domain -c $weight -t $domain # if there is enough node, apply layout -apply_layout "$garage_command" +garage_layout_apply if [ -n "$bootstrap_peers" ] then - garage_connect "$garage_command" "$bootstrap_peers" + garage_connect "$bootstrap_peers" fi -self_bootstrap_peers="$($garage_command node id --quiet)" -garage_layout="$($garage_command layout show)" +self_bootstrap_peers="$($garage node id --quiet)" +garage_layout="$($garage layout show)" ynh_app_setting_set --app=$app --key=garage_layout --value="$garage_layout" #================================================= diff --git a/scripts/remove b/scripts/remove index e6c5473..50cab65 100755 --- a/scripts/remove +++ b/scripts/remove @@ -13,9 +13,9 @@ source /usr/share/yunohost/helpers # REMOVE NODE CONFIGURATION #================================================= -$install_dir/garage -c $install_dir/garage.toml layout remove "$secret_node_id" +$garage layout remove "$secret_node_id" -apply_layout "$install_dir/garage -c $install_dir/garage.toml " +garage_layout_apply if [ $? -ne 0 ] then ynh_print_warn --message="Unable to remove the node. Maybe the number of node staying alive is not enough" diff --git a/scripts/restore b/scripts/restore index ddbebe5..4062cf3 100755 --- a/scripts/restore +++ b/scripts/restore @@ -67,16 +67,14 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" sleep 2 -garage_command="$install_dir/garage -c $install_dir/garage.toml" - # define node -$garage_command layout assign $secret_node_id -z $domain -c $weight -t $domain +$garage layout assign $secret_node_id -z $domain -c $weight -t $domain # if there is enough node, apply layout -apply_layout "$garage_command" +garage_layout_apply if [ -n "$bootstrap_peers" ] then - garage_connect "$garage_command" "$bootstrap_peers" + garage_connect "$bootstrap_peers" fi #=================================================