From c7fd01dd64a3ce8b7c66bd4599df4a68ac31d771 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 5 Jun 2021 15:13:58 +0200 Subject: [PATCH] Add logs --- scripts/backup | 6 ++++++ scripts/install | 22 ++++++++++++++++++++++ scripts/remove | 10 ++++++---- scripts/restore | 11 +++++++++++ scripts/upgrade | 8 ++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/scripts/backup b/scripts/backup index b30dde3..ffa106f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -50,6 +50,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" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 59878bb..8148aab 100644 --- a/scripts/install +++ b/scripts/install @@ -122,6 +122,28 @@ ynh_use_nodejs ls -lah ) +# chown -R $app $final_path + +# pushd $final_path +# ynh_use_nodejs +# ynh_exec_warn_less ynh_exec_as "$app" PATH="$nodejs_path:$PATH" "$nodejs_path/npm" install --save --loglevel warn +# ynh_exec_warn_less ynh_exec_as "$app" PATH="$nodejs_path:$PATH" "$nodejs_path/npm" run build +# ls -lah +# popd + +#================================================= +# HANDLE LOG FILES AND LOGROTATE +#================================================= +ynh_script_progression --message="Configuring log rotation..." + +# 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 + #================================================= # SETUP SYSTEMD #================================================= diff --git a/scripts/remove b/scripts/remove index 6f0e0cb..de950d3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -69,12 +69,14 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- ynh_remove_nginx_config #================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE OTHER FILES +# REMOVE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Removing logrotate configuration..." -ynh_secure_remove "/var/log/$app" +ynh_secure_remove --file="/var/log/$app" + +# Remove the app-specific logrotate config +ynh_remove_logrotate #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index 1e8d20e..5e39b35 100644 --- a/scripts/restore +++ b/scripts/restore @@ -54,6 +54,17 @@ ynh_script_progression --message="Recreating the dedicated system user..." --wei # Create the dedicated user (if not existing) ynh_system_user_create --username=$app --home_dir="$final_path" +#================================================= +# HANDLE LOG FILES AND LOGROTATE +#================================================= + +mkdir -p /var/log/$app +touch /var/log/$app/$app.log +chown -R $app /var/log/$app + +# Restore logrotate configuration +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # RESTORE THE APP MAIN DIR #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 66d150e..741354e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -125,6 +125,14 @@ ynh_add_systemd_config # Add Mumble as a YunoHost service yunohost service add $app --description="Mumble web interface" --log="/var/log/$app/$app.log" +#================================================= +# SETUP LOGROTATE +#================================================= +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append --specific_user=$app/$app + #================================================= # START SYSTEMD SERVICE #=================================================