update script to improve garage configuration
This commit is contained in:
parent
bbcc67e597
commit
abff1b3ce2
6 changed files with 32 additions and 27 deletions
2
conf/mount_disk.sh
Normal file → Executable file
2
conf/mount_disk.sh
Normal file → Executable file
|
@ -1,4 +1,4 @@
|
||||||
#!bash
|
#!/bin/bash
|
||||||
datadir=$1
|
datadir=$1
|
||||||
format=$2
|
format=$2
|
||||||
i=0
|
i=0
|
||||||
|
|
|
@ -6,7 +6,7 @@ Wants=network-online.target
|
||||||
[Service]
|
[Service]
|
||||||
User=__APP__
|
User=__APP__
|
||||||
Environment='RUST_LOG=garage=info' 'RUST_BACKTRACE=1'
|
Environment='RUST_LOG=garage=info' 'RUST_BACKTRACE=1'
|
||||||
ExecStartPre=+__FINALPATH__/mount_disk.sh __FINALPATH__
|
ExecStartPre=+__FINALPATH__/mount_disk.sh __FINALPATH__ __NBD_INDEX__
|
||||||
ExecStart=__FINALPATH__/garage -c __FINALPATH__/garage.toml server
|
ExecStart=__FINALPATH__/garage -c __FINALPATH__/garage.toml server
|
||||||
StateDirectory=garage
|
StateDirectory=garage
|
||||||
DynamicUser=true
|
DynamicUser=true
|
||||||
|
|
20
conf/umount_disk.sh
Normal file → Executable file
20
conf/umount_disk.sh
Normal file → Executable file
|
@ -1,16 +1,4 @@
|
||||||
#!bash
|
#!/bin/bash
|
||||||
datadir=$1
|
nbd=$1
|
||||||
format=$2
|
umount /dev/nbd$nbd
|
||||||
i=0
|
qemu-nbd --disconnect /dev/nbd$nbd
|
||||||
while $(fdisk -l /dev/nbd$i 1&>2 /dev/null)
|
|
||||||
do
|
|
||||||
i=$(( i + 1 ))
|
|
||||||
done
|
|
||||||
echo $i
|
|
||||||
modprobe nbd max_part=$(( i + 1 ))
|
|
||||||
qemu-nbd --connect /dev/nbd$i $datadir/garage.qcow2
|
|
||||||
if [[ "$format" = "true" ]]
|
|
||||||
then
|
|
||||||
mkfs.ext4 /dev/nbd$i > /dev/null
|
|
||||||
fi
|
|
||||||
mount /dev/nbd$i $datadir/data/
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
datadir=$(ynh_app_setting_get $app datadir)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
|
|
|
@ -25,7 +25,6 @@ ynh_abort_if_errors
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
#port mandatory for garage
|
#port mandatory for garage
|
||||||
port=3901
|
|
||||||
ip=$(get_ip)
|
ip=$(get_ip)
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ ynh_script_progression --message="Validating installation parameters..." --time
|
||||||
### If the app provides an internal web server (or uses another application server such as uWSGI), the final path should be "/opt/yunohost/$app"
|
### If the app provides an internal web server (or uses another application server such as uWSGI), the final path should be "/opt/yunohost/$app"
|
||||||
final_path=/opt/yunohost/$app
|
final_path=/opt/yunohost/$app
|
||||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||||
ynh_port_available --port=3900|| ynh_die --message="Port 3900 is needs to be available for this app"
|
|
||||||
if [[ -n "$rpc_secret" ]]
|
if [[ -n "$rpc_secret" ]]
|
||||||
then
|
then
|
||||||
echo "$rpc_secret" | grep -E ^[0-9a-f]{64}$ || ynh_die --message="rpc_secret have to be a 32-byte hex-encoded random string. See https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/ for more information"
|
echo "$rpc_secret" | grep -E ^[0-9a-f]{64}$ || ynh_die --message="rpc_secret have to be a 32-byte hex-encoded random string. See https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/ for more information"
|
||||||
|
@ -109,10 +108,12 @@ ynh_script_progression --message="Finding available ports..." --time --weight=1
|
||||||
|
|
||||||
# Find an available port
|
# Find an available port
|
||||||
|
|
||||||
|
port=$(ynh_find_port --port=3901)
|
||||||
port_api=$(ynh_find_port --port=3900)
|
port_api=$(ynh_find_port --port=3900)
|
||||||
port_web=$(ynh_find_port --port=3902)
|
port_web=$(ynh_find_port --port=3902)
|
||||||
port_admin=$(ynh_find_port --port=3903)
|
port_admin=$(ynh_find_port --port=3903)
|
||||||
|
|
||||||
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
||||||
ynh_app_setting_set --app=$app --key=port_api --value=$port_api
|
ynh_app_setting_set --app=$app --key=port_api --value=$port_api
|
||||||
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
|
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
|
||||||
ynh_app_setting_set --app=$app --key=port_admin --value=$port_admin
|
ynh_app_setting_set --app=$app --key=port_admin --value=$port_admin
|
||||||
|
@ -122,7 +123,7 @@ ynh_app_setting_set --app=$app --key=port_admin --value=$port_admin
|
||||||
|
|
||||||
# Open the port
|
# Open the port
|
||||||
ynh_script_progression --message="Configuring firewall..." --time --weight=1
|
ynh_script_progression --message="Configuring firewall..." --time --weight=1
|
||||||
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
|
ynh_exec_warn_less yunohost firewall allow TCP $port
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL DEPENDENCIES
|
# INSTALL DEPENDENCIES
|
||||||
|
@ -214,6 +215,7 @@ mkdir -p $datadir/data
|
||||||
# to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size.
|
# to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size.
|
||||||
qemu-img create -f qcow2 $datadir/garage_data.qcow2 "$weight"G
|
qemu-img create -f qcow2 $datadir/garage_data.qcow2 "$weight"G
|
||||||
nbd_index=$($final_path/mount_disk.sh "$datadir" true)
|
nbd_index=$($final_path/mount_disk.sh "$datadir" true)
|
||||||
|
ynh_app_setting_set --app=$app --key=nbd_index --value=$nbd_index
|
||||||
|
|
||||||
# FIXME: this should be managed by the core in the future
|
# FIXME: this should be managed by the core in the future
|
||||||
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
# Here, as a packager, you may have to tweak the ownerhsip/permissions
|
||||||
|
@ -225,8 +227,7 @@ chmod 750 "$datadir"
|
||||||
chmod -R o-rwx "$datadir"
|
chmod -R o-rwx "$datadir"
|
||||||
chown -R $app:$app "$datadir"
|
chown -R $app:$app "$datadir"
|
||||||
|
|
||||||
umount /dev/nbd$nbd_index
|
$final_path/umount_disk.sh $nbd_index
|
||||||
qemu-img --disconnect /dev/nbd$nbd_index
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD A CONFIGURATION
|
# ADD A CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -369,15 +370,22 @@ ynh_script_progression --message="Configuring garage..." --time --weight=1
|
||||||
|
|
||||||
garage_command="$final_path/garage -c $final_path/garage.toml"
|
garage_command="$final_path/garage -c $final_path/garage.toml"
|
||||||
|
|
||||||
gagare_id=$($garage_command node id -q | cut -d '@' -f1)
|
garage_id=$($garage_command node id -q | cut -d '@' -f1)
|
||||||
|
|
||||||
$garage_command assign $garage_id -z $domain -c
|
$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
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# Send email to admin
|
# Send email to admin
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_send_readme_to_admin --app_message=app_message
|
app_message="your garage node have been installed. You can now connect to other nodes with the following identifiers : \
|
||||||
|
rpc_secret: $rpc_secret
|
||||||
|
bootstrap_peers: $bootstrap_peers"
|
||||||
|
|
||||||
|
ynh_send_readme_to_admin --app_message=$app_message
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
|
|
|
@ -23,7 +23,7 @@ port_api=$(ynh_app_setting_get --app=$app --key=port_api)
|
||||||
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
|
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
|
||||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||||
bootstrap_peers=$(ynh_app_setting_get --app=$app --key=bootstrap_peers)
|
bootstrap_peers=$(ynh_app_setting_get --app=$app --key=bootstrap_peers)
|
||||||
|
nbd_index=$(ynh_app_setting_get --app=$app --key=nbd_index)
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD REMOVE
|
# STANDARD REMOVE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -54,6 +54,14 @@ ynh_script_progression --message="Removing logrotate configuration..." --time --
|
||||||
ynh_remove_logrotate
|
ynh_remove_logrotate
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE VIRTUAL DISK
|
||||||
|
#=================================================
|
||||||
|
ynh_script_progression --message="umount virtual disk..." --time --weight=1
|
||||||
|
|
||||||
|
# Remove the app directory securely
|
||||||
|
$final_path/umount_disk.sh $nbd_index
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue