From b9f09dd2e682e996bed5d4aa187666df0531af28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 10 Dec 2023 20:40:31 +0100 Subject: [PATCH 1/5] Update tests.toml --- tests.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests.toml b/tests.toml index 91daf17..cfc9cf6 100644 --- a/tests.toml +++ b/tests.toml @@ -4,4 +4,6 @@ test_format = 1.0 # ------------ # Tests to run - # ------------ \ No newline at end of file + # ------------ + + args.weight = "10" \ No newline at end of file From 37f93ac72c4293a45bf36620d64840f2aaeca9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 10 Dec 2023 20:52:41 +0100 Subject: [PATCH 2/5] cleaning --- doc/POST_INSTALL.md | 6 ++++++ scripts/backup | 5 ----- scripts/change_url | 8 ++++---- scripts/install | 36 +++++++++++------------------------- scripts/remove | 20 ++------------------ 5 files changed, 23 insertions(+), 52 deletions(-) create mode 100644 doc/POST_INSTALL.md diff --git a/doc/POST_INSTALL.md b/doc/POST_INSTALL.md new file mode 100644 index 0000000..b420b12 --- /dev/null +++ b/doc/POST_INSTALL.md @@ -0,0 +1,6 @@ +Your Garage node have been installed. You can now connect to other nodes with the following identifiers : + + rpc_secret: __RPC_SECRET__ + bootstrap_peers: __SELF_BOOTSTRAP_PEERS__ + +Current garage layout: __GARAGE_LAYOUT__ diff --git a/scripts/backup b/scripts/backup index 6524c9b..80e2ce2 100755 --- a/scripts/backup +++ b/scripts/backup @@ -15,11 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_print_info --message="Declaring files to be backed up..." -### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs -### to be backuped and not an actual copy of any file. The actual backup that -### creates and fill the archive with the files happens in the core after this -### script is called. Hence ynh_backups calls takes basically 0 seconds to run. - #================================================= # BACKUP THE APP MAIN DIR #================================================= diff --git a/scripts/change_url b/scripts/change_url index 643b687..ae914ad 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -14,14 +14,14 @@ source /usr/share/yunohost/helpers #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time +ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." --time +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_change_url_nginx_config @@ -30,7 +30,7 @@ ynh_change_url_nginx_config #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time +ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" @@ -38,4 +38,4 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --time --last +ynh_script_progression --message="Change of URL completed for $app" --last diff --git a/scripts/install b/scripts/install index a48b89b..73c047b 100755 --- a/scripts/install +++ b/scripts/install @@ -27,7 +27,7 @@ fi #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." +ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app=$app --key=rpc_secret --value=$rpc_secret ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers @@ -35,7 +35,7 @@ ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression --message="Setting up source files..." --weight=1 ynh_setup_source --dest_dir="$install_dir" # chmod +x $install_dir/garage # this file doesnt seem to exist ... remove this line ? @@ -43,7 +43,7 @@ ynh_setup_source --dest_dir="$install_dir" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." +ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config @@ -51,7 +51,7 @@ ynh_add_nginx_config #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="mount_disk.sh" --destination="$install_dir/mount_disk.sh" ynh_add_config --template="umount_disk.sh" --destination="$install_dir/umount_disk.sh" @@ -64,7 +64,7 @@ chown $app:$app "$install_dir/garage.toml" #================================================= # CREATE DATA DIRECTORY #================================================= -ynh_script_progression --message="Creating a data directory..." --weight=5 +ynh_script_progression --message="Creating a data directory..." --weight=5 if [[ "$system_is_inside_container" == "true" ]] then @@ -79,7 +79,7 @@ fi #================================================= # ADD REGEN-CONF HOOK #================================================= -ynh_script_progression --message="Adding regen-conf hook..." +ynh_script_progression --message="Adding regen-conf hook..." --weight=1 ynh_add_config --template="regenconf_nginx_garage" --destination="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" yunohost tools regen-conf nginx @@ -87,7 +87,7 @@ yunohost tools regen-conf nginx #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config @@ -100,7 +100,7 @@ yunohost service add $app --description="s3 storage" --log="/var/log/$app/$app.l #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" @@ -108,7 +108,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap #================================================= # CONFIGURE GARAGE #================================================= -ynh_script_progression --message="Configuring garage..." +ynh_script_progression --message="Configuring garage..." --weight=1 garage_command="$install_dir/garage -c $install_dir/garage.toml" @@ -138,24 +138,10 @@ fi self_bootstrap_peers="$($garage_command node id --quiet)" garage_layout="$($garage_command layout show)" - -#================================================= -# Send email to admin -#================================================= -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: $self_bootstrap_peers - -Current garage layout : - -$garage_layout" - -ynh_send_readme_to_admin --app_message="$app_message" +ynh_app_setting_set --app=$app --key=garage_layout --value=$garage_layout #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 806a3f4..c5a9009 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,4 +1,4 @@ - #!/bin/bash +#!/bin/bash #================================================= # GENERIC START @@ -9,10 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= - #================================================= # REMOVE NODE CONFIGURATION #================================================= @@ -24,7 +20,6 @@ then ynh_print_warn --message="unable to remove the node. Maybe the number of node staying alive is not enough" fi - #================================================= # STANDARD REMOVE #================================================= @@ -60,7 +55,7 @@ then #================================================= # REMOVE VIRTUAL DISK #================================================= - ynh_script_progression --message="umount virtual disk..." + ynh_script_progression --message="Umount virtual disk..." # Remove the app directory securely $install_dir/umount_disk.sh @@ -82,17 +77,6 @@ ynh_remove_nginx_config ynh_replace_string --replace_string="server_name $domain" --match_string="server_name $domain *.$domain" --target_file="/etc/nginx/conf.d/$domain.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.conf" - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - #================================================= # SPECIFIC REMOVE #================================================= From 060b38422d849ee3bfefae7a923c8f1469b11c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 10 Dec 2023 20:53:23 +0100 Subject: [PATCH 3/5] Update manifest.toml --- manifest.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.toml b/manifest.toml index 142ff9e..f9ca10c 100644 --- a/manifest.toml +++ b/manifest.toml @@ -77,6 +77,7 @@ ram.runtime = "50M" [resources.install_dir] [resources.data_dir] + subdirs = ["data"] [resources.permissions] main.url = "/" From ed30446be7f7b60d3d6b690e56f4b6cb344c5c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 10 Dec 2023 20:56:18 +0100 Subject: [PATCH 4/5] Update tests.toml --- tests.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests.toml b/tests.toml index cfc9cf6..137a83f 100644 --- a/tests.toml +++ b/tests.toml @@ -6,4 +6,9 @@ test_format = 1.0 # Tests to run # ------------ - args.weight = "10" \ No newline at end of file + exclude = ["install.private", "install.root", "install.subdir", "install.multi"] + + # ------------------------------- + # Default args to use for install + # ------------------------------- + args.weight = "10" From 3a53cc86965f878a665bab322ad96025a840a11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 10 Dec 2023 21:01:43 +0100 Subject: [PATCH 5/5] cleaning --- conf/mount_disk.sh | 1 - manifest.toml | 2 +- scripts/_common.sh | 4 ++-- scripts/backup | 2 -- scripts/change_url | 4 ++-- scripts/install | 2 +- scripts/remove | 39 +++------------------------------------ scripts/restore | 39 ++++----------------------------------- scripts/upgrade | 26 +++++--------------------- 9 files changed, 18 insertions(+), 101 deletions(-) diff --git a/conf/mount_disk.sh b/conf/mount_disk.sh index 0c09ab1..53f2acc 100755 --- a/conf/mount_disk.sh +++ b/conf/mount_disk.sh @@ -18,7 +18,6 @@ then echo "formatting /dev/nbd$i" mkfs.ext4 /dev/nbd$i fi - mkdir -p $data_dir/data chown __APP__:__APP__ $data_dir/data mount /dev/nbd$i $data_dir/data/ fi diff --git a/manifest.toml b/manifest.toml index f9ca10c..3ee43a4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -77,7 +77,7 @@ ram.runtime = "50M" [resources.install_dir] [resources.data_dir] - subdirs = ["data"] + subdirs = ["data", "metadata"] [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index ae268d3..9408df1 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -32,7 +32,7 @@ garage_connect() { i=$(( i + 1 )) if [ $i -gt 30 ] then - ynh_die --message="unable to get layout from remote peer" + ynh_die --message="Unable to get layout from remote peer" fi sleep 1 done @@ -48,7 +48,7 @@ apply_layout() { then $garage_command layout apply --version $layout_version else - ynh_print_warn --message="unable to apply layout. No enough nodes" + ynh_print_warn --message="Unable to apply layout. No enough nodes" return 0 fi } diff --git a/scripts/backup b/scripts/backup index 80e2ce2..d306ce7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -27,8 +27,6 @@ ynh_backup --src_path="$install_dir" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# SPECIFIC BACKUP #================================================= # BACKUP LOGROTATE #================================================= diff --git a/scripts/change_url b/scripts/change_url index ae914ad..3a9b28d 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -16,7 +16,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" #================================================= # MODIFY URL IN NGINX CONF @@ -32,7 +32,7 @@ ynh_change_url_nginx_config #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 73c047b..2791de0 100755 --- a/scripts/install +++ b/scripts/install @@ -103,7 +103,7 @@ yunohost service add $app --description="s3 storage" --log="/var/log/$app/$app.l ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # CONFIGURE GARAGE diff --git a/scripts/remove b/scripts/remove index c5a9009..c7210aa 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,12 +12,13 @@ source /usr/share/yunohost/helpers #================================================= # REMOVE NODE CONFIGURATION #================================================= + $install_dir/garage -c $install_dir/garage.toml layout remove "$node_id" apply_layout "$install_dir/garage -c $install_dir/garage.toml " if [ $? -ne 0 ] 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" fi #================================================= @@ -33,43 +34,20 @@ then yunohost service remove $app fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - # Remove the app-specific logrotate config ynh_remove_logrotate - if [[ "$system_is_inside_container" == "true" ]] then - #================================================= - # REMOVE VIRTUAL DISK - #================================================= ynh_script_progression --message="Umount virtual disk..." # Remove the app directory securely $install_dir/umount_disk.sh fi -#================================================= -# REMOVE NGINX HOOK -#================================================= - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." - # Remove the dedicated NGINX config ynh_remove_nginx_config @@ -77,20 +55,9 @@ ynh_remove_nginx_config ynh_replace_string --replace_string="server_name $domain" --match_string="server_name $domain *.$domain" --target_file="/etc/nginx/conf.d/$domain.conf" ynh_store_file_checksum --file="/etc/nginx/conf.d/$domain.conf" -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." - # Remove the log files ynh_secure_remove --file="/var/log/$app" -#================================================= -# GENERIC FINALIZATION -#================================================= - ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" yunohost tools regen-conf nginx @@ -98,4 +65,4 @@ yunohost tools regen-conf nginx # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 82d142d..eea021b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,8 +24,6 @@ chown -R $app:$app "$install_dir" #================================================= ynh_script_progression --message="Restoring the data directory..." -mkdir -p "$data_dir/data" - if [[ "$system_is_inside_container" == "true" ]] then # to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size. @@ -33,25 +31,9 @@ then $install_dir/mount_disk.sh true fi - -# # FIXME: this should be managed by the core in the future -# Here, as a packager, you may have to tweak the ownerhsip/permissions -# such that the appropriate users (e.g. maybe www-data) can access -# files in some cases. -# But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - -# this will be treated as a security issue. -chmod 750 "$data_dir" chmod -R o-rwx "$data_dir" chown -R $app:$app "$data_dir" -#================================================= -# SPECIFIC RESTORATION -#================================================= - -# Open the port - ynh_script_progression --message="Configuring firewall..." - ynh_exec_warn_less yunohost firewall allow TCP $port - #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= @@ -63,26 +45,11 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" yunohost tools regen-conf nginx -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." - ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." - ynh_restore_file --origin_path="/etc/logrotate.d/$app" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - yunohost service add $app --description="s3 storage" --log="/var/log/$app/$app.log" --needs_exposed_ports $port #================================================= @@ -93,7 +60,8 @@ ynh_script_progression --message="Starting a systemd service..." #recreate log folder mkdir /var/log/$app -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" + #================================================= # RECREATE CONFIGURATION #================================================= @@ -111,12 +79,13 @@ if [ -n "$bootstrap_peers" ] then garage_connect "$garage_command" "$bootstrap_peers" fi + #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server..." ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index bc5deea..166be47 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,7 +22,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= ynh_script_progression --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -48,33 +48,17 @@ ynh_add_nginx_config ynh_add_config --template="regenconf_nginx_garage" --destination="/usr/share/yunohost/hooks/conf_regen/98-nginx_$app" yunohost tools regen-conf nginx -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." - # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append -ynh_script_progression --message="Updating a configuration file..." - #================================================= # UPDATE A CONFIG FILE #================================================= -### Same as during install -### -### The file will automatically be backed-up if it's found to be manually modified (because -### ynh_add_config keeps track of the file's checksum) +ynh_script_progression --message="Updating a configuration file..." + ynh_add_config --template="garage.toml" --destination="$install_dir/garage.toml" #================================================= @@ -89,10 +73,10 @@ yunohost service add $app --description="s3 storage" --log="/var/log/$app/$app.l #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression --message="Upgrade of $app completed" --last