mirror of
https://github.com/YunoHost-Apps/garage_ynh.git
synced 2024-09-03 18:36:32 +02:00
Further simplify, homogeneize garage command call syntax
This commit is contained in:
parent
d831710621
commit
f472785ac6
5 changed files with 30 additions and 45 deletions
|
@ -24,15 +24,16 @@ fi
|
||||||
# PERSONAL HELPERS
|
# PERSONAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
garage="$install_dir/garage -c $install_dir/garage.toml"
|
||||||
|
|
||||||
garage_connect() {
|
garage_connect() {
|
||||||
local command="$1"
|
local peer="$1"
|
||||||
local peer="$2"
|
|
||||||
# connect to cluster
|
# connect to cluster
|
||||||
$command node connect "$peer"
|
$garage node connect "$peer"
|
||||||
sleep 2
|
sleep 2
|
||||||
# wait until layout is updated
|
# wait until layout is updated
|
||||||
local i=0
|
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 ))
|
i=$(( i + 1 ))
|
||||||
if [ $i -gt 30 ]
|
if [ $i -gt 30 ]
|
||||||
then
|
then
|
||||||
|
@ -43,24 +44,14 @@ garage_connect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
apply_layout() {
|
garage_layout_apply() {
|
||||||
|
$garage layout show 2>/dev/null
|
||||||
garage_command=$1
|
if [ "$($garage layout show | grep 'This new layout cannot yet be applied')" ]
|
||||||
$garage_command layout show 2>/dev/null
|
|
||||||
if [ "$($garage_command layout show | grep 'This new layout cannot yet be applied')" ]
|
|
||||||
then
|
then
|
||||||
ynh_print_warn --message="Unable to apply layout. No enough nodes"
|
ynh_print_warn --message="Unable to apply layout. No enough nodes"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
local layout_version=$($garage_command layout show 2>/dev/null | grep -Po -- "(?<=--version).*" | head -1 | xargs)
|
local layout_version=$($garage layout show 2>/dev/null | grep -Po -- "(?<=--version).*" | head -1 | xargs)
|
||||||
$garage_command layout apply --version $layout_version
|
$garage layout apply --version $layout_version
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# EXPERIMENTAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FUTURE OFFICIAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
|
@ -10,13 +10,11 @@ source /usr/share/yunohost/helpers
|
||||||
data_dir=$(ynh_app_setting_get $app data_dir)
|
data_dir=$(ynh_app_setting_get $app data_dir)
|
||||||
secret_node_id=$(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
|
then
|
||||||
nbd_index=$(cat $data_dir/nbd_index)
|
nbd_index=$(cat $data_dir/nbd_index)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
command="$install_dir/garage -c $install_dir/garage.toml"
|
|
||||||
|
|
||||||
set__weight() {
|
set__weight() {
|
||||||
if system_is_inside_container
|
if system_is_inside_container
|
||||||
then
|
then
|
||||||
|
@ -39,29 +37,29 @@ set__weight() {
|
||||||
systemctl start $app
|
systemctl start $app
|
||||||
sleep 3
|
sleep 3
|
||||||
fi
|
fi
|
||||||
$command layout assign $secret_node_id -c $weight 2>/dev/null
|
$garage layout assign $secret_node_id -c $weight 2>/dev/null
|
||||||
apply_layout "$command"
|
garage_layout_apply
|
||||||
ynh_app_setting_set --app=$app --key=weight --value=$weight
|
ynh_app_setting_set --app=$app --key=weight --value=$weight
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set__bootstrap_peers() {
|
set__bootstrap_peers() {
|
||||||
garage_connect "$command" "$bootstrap_peers" 2>/dev/null
|
garage_connect "$bootstrap_peers" 2>/dev/null
|
||||||
apply_layout "$command"
|
garage_layout_apply
|
||||||
ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers
|
ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers
|
||||||
}
|
}
|
||||||
|
|
||||||
get__node() {
|
get__node() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
ask:
|
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*"
|
*This id is a sensitive information and should not be shared with anyone else than other nodes of the cluster*"
|
||||||
style: "info"
|
style: "info"
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
get__status() {
|
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
|
cat << EOF
|
||||||
ask:
|
ask:
|
||||||
en: "**Current garage layout**: \n
|
en: "**Current garage layout**: \n
|
||||||
|
|
|
@ -125,32 +125,30 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring garage..." --weight=1
|
ynh_script_progression --message="Configuring garage..." --weight=1
|
||||||
|
|
||||||
garage_command="$install_dir/garage -c $install_dir/garage.toml"
|
|
||||||
|
|
||||||
i=0
|
i=0
|
||||||
# sometimes server need some time to start
|
# 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=$(( 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
|
sleep 1
|
||||||
done
|
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
|
ynh_app_setting_set --app=$app --key=secret_node_id --value=$secret_node_id
|
||||||
|
|
||||||
|
|
||||||
# define node
|
# 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
|
# if there is enough node, apply layout
|
||||||
apply_layout "$garage_command"
|
garage_layout_apply
|
||||||
|
|
||||||
if [ -n "$bootstrap_peers" ]
|
if [ -n "$bootstrap_peers" ]
|
||||||
then
|
then
|
||||||
garage_connect "$garage_command" "$bootstrap_peers"
|
garage_connect "$bootstrap_peers"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
self_bootstrap_peers="$($garage_command node id --quiet)"
|
self_bootstrap_peers="$($garage node id --quiet)"
|
||||||
garage_layout="$($garage_command layout show)"
|
garage_layout="$($garage layout show)"
|
||||||
ynh_app_setting_set --app=$app --key=garage_layout --value="$garage_layout"
|
ynh_app_setting_set --app=$app --key=garage_layout --value="$garage_layout"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -13,9 +13,9 @@ source /usr/share/yunohost/helpers
|
||||||
# REMOVE NODE CONFIGURATION
|
# 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 ]
|
if [ $? -ne 0 ]
|
||||||
then
|
then
|
||||||
ynh_print_warn --message="Unable to remove the node. Maybe the number of node staying alive is not enough"
|
ynh_print_warn --message="Unable to remove the node. Maybe the number of node staying alive is not enough"
|
||||||
|
|
|
@ -67,16 +67,14 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
|
||||||
|
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
garage_command="$install_dir/garage -c $install_dir/garage.toml"
|
|
||||||
|
|
||||||
# define node
|
# 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
|
# if there is enough node, apply layout
|
||||||
apply_layout "$garage_command"
|
garage_layout_apply
|
||||||
|
|
||||||
if [ -n "$bootstrap_peers" ]
|
if [ -n "$bootstrap_peers" ]
|
||||||
then
|
then
|
||||||
garage_connect "$garage_command" "$bootstrap_peers"
|
garage_connect "$bootstrap_peers"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue