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