From 3adefc5e818ed117f8c5e9abc4f0fe15232160db Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Mon, 2 Aug 2021 23:46:13 +0200 Subject: [PATCH] Fix --- scripts/backup | 10 +++++++++- scripts/change_url | 25 +++++++------------------ scripts/install | 11 ++++++++--- scripts/remove | 20 +++++++++++++++++++- scripts/restore | 24 ++++++++++++++++++++++-- scripts/upgrade | 27 +++++++++++++++++++++------ 6 files changed, 86 insertions(+), 31 deletions(-) diff --git a/scripts/backup b/scripts/backup index 735c496..e492fa1 100755 --- a/scripts/backup +++ b/scripts/backup @@ -37,6 +37,8 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" + ynh_backup --src_path="/etc/default/$app" + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= @@ -49,6 +51,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/systemd/system/$app.service" +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP THE POSTQRESQL DATABASE #================================================= @@ -60,4 +68,4 @@ ynh_psql_dump_db --database="$db_name" > db.sql # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for Metabase. (YunoHost will then actually copy those files to the archive)." +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index 126010e..8b85a08 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,20 +24,15 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) -# Add settings here as needed by your application -#db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#db_user=$db_name -#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -72,14 +67,14 @@ fi #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +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 --weight=1 +ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -105,25 +100,19 @@ then ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi -#================================================= -# SPECIFIC MODIFICATIONS -#================================================= -# ... -#================================================= - #================================================= # GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +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" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1 +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload @@ -131,4 +120,4 @@ ynh_systemd_action --service_name=nginx --action=reload # 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 4d15d04..12d6afd 100755 --- a/scripts/install +++ b/scripts/install @@ -129,8 +129,13 @@ chown $app "/etc/default/$app" # SECURE FILES AND DIRECTORIES #================================================= -touch /var/log/$app.log -chown $app: /var/log/$app.log +# Create log directory +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown -R $app /var/log/$app + +# Setup logrotate +ynh_use_logrotate --specific_user=$app/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -169,4 +174,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of Metabase completed" --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index f457311..8d06a0b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -67,6 +67,14 @@ ynh_script_progression --message="Removing Metabase main directory..." --weight= # Remove the app directory securely ynh_secure_remove --file="$final_path" +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_script_progression --message="Removing the app configuration file..." --weight=1 + +# Remove the app directory securely +ynh_secure_remove --file="/etc/default/$app" + #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -75,6 +83,16 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." + +ynh_secure_remove --file="/var/log/$app" + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # GENERIC FINALIZATION #================================================= @@ -89,4 +107,4 @@ ynh_system_user_delete --username=$app # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of Metabase completed" --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 313226d..f622c9e 100755 --- a/scripts/restore +++ b/scripts/restore @@ -63,7 +63,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring Metabase main directory..." --weight=2 +ynh_script_progression --message="Restoring the app main directory..." --weight=2 ynh_restore_file --origin_path="$final_path" @@ -72,6 +72,15 @@ chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" chmod +x $final_path/metabase.jar +#================================================= +# SETUP CONFIG +#================================================= +ynh_script_progression --message="Restoring a configuration file..." --weight=1 + +ynh_restore_file --origin_path="/etc/default/$app" +chmod 640 "/etc/default/$app" +chown $app "/etc/default/$app" + #================================================= # INSTALL DEPENDENCIES #================================================= @@ -88,6 +97,17 @@ ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +#================================================= +# HANDLE LOG FILES AND LOGROTATE +#================================================= + +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown $app -R /var/log/$app + +# Restore logrotate configuration +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # SPECIFIC RESTORATION #================================================= @@ -125,4 +145,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for Metabase" --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index e31f2e6..04c8047 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -117,13 +117,28 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=3 ynh_add_systemd_config #================================================= -# GENERIC FINALIZATION -#================================================= -# SECURE FILES AND DIRECTORIES +# SETUP CONFIG #================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 -chown $app: /var/log/$app.log -chmod 640 /etc/default/$app +touch /etc/default/$app +ynh_add_config --template="../conf/metabase" --destination="/etc/default/$app" + +chmod 640 "/etc/default/$app" +chown $app "/etc/default/$app" + +#================================================= +# HANDLE LOG FILES AND LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --weight=3 + +# Create log directory +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown -R $app /var/log/$app + +# Setup logrotate +ynh_use_logrotate --specific_user=$app/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -151,4 +166,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of Metabase completed" --last +ynh_script_progression --message="Upgrade of $app completed" --last