From 05fc01680c634574da7a47b9ac1277575788ad87 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Mon, 27 Jun 2022 16:47:05 -0400 Subject: [PATCH] Use logrotate --- scripts/backup | 8 +++++++- scripts/install | 13 ++++++++++--- scripts/remove | 11 +++++++++-- scripts/restore | 14 +++++++++++--- scripts/upgrade | 13 ++++++++++--- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/scripts/backup b/scripts/backup index d72c557..3497042 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +ynh_clean_setup() { true } # Exit if an error occurs during the execution of the script @@ -49,6 +49,12 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP +#================================================= +# BACKUP LOGROTATE +#================================================= + +ynh_backup --src_path="/etc/logrotate.d/$app" + #================================================= # BACKUP SYSTEMD #================================================= diff --git a/scripts/install b/scripts/install index bdcb2ff..9647219 100755 --- a/scripts/install +++ b/scripts/install @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +ynh_clean_setup() { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script @@ -144,6 +144,14 @@ set_permissions #================================================= # GENERIC FINALIZATION +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." --time --weight=1 + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= @@ -165,8 +173,7 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$ap ynh_script_progression --message="Configuring permissions..." --weight=1 # Make app public if necessary -if [ $is_public -eq 1 ] -then +if [ $is_public -eq 1 ]; then # Everyone can access the app. # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" diff --git a/scripts/remove b/scripts/remove index 4828414..1c7ac8b 100755 --- a/scripts/remove +++ b/scripts/remove @@ -27,8 +27,7 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then +if ynh_exec_warn_less yunohost service status $app >/dev/null; then ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app fi @@ -41,6 +40,14 @@ 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..." --time --weight=1 + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE APP MAIN DIR #================================================= diff --git a/scripts/restore b/scripts/restore index b0874fb..ec57d65 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +ynh_clean_setup() { ynh_clean_check_starting } # Exit if an error occurs during the execution of the script @@ -36,8 +36,8 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path || + ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -88,6 +88,14 @@ ynh_script_progression --message="Restoring the systemd configuration..." --weig 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..." --time --weight=1 + +ynh_use_logrotate --non-append +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 6b444e8..7ca5665 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -41,7 +41,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade -ynh_clean_setup () { +ynh_clean_setup() { ynh_clean_check_starting # Restore it if the upgrade fails ynh_restore_upgradebackup @@ -70,8 +70,7 @@ ynh_system_user_create --username=$app --home_dir="$final_path" # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then +if [ "$upgrade_type" == "UPGRADE_APP" ]; then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src @@ -131,6 +130,14 @@ set_permissions #================================================= # GENERIC FINALIZATION +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + #================================================= # INTEGRATE SERVICE IN YUNOHOST #=================================================