From 1d825936e1231554be33b52021e91014b56c6acf Mon Sep 17 00:00:00 2001 From: Tagada <36127788+Tagadda@users.noreply.github.com> Date: Tue, 1 Aug 2023 04:15:46 +0200 Subject: [PATCH] Use logrotate --- conf/glitchsoc-sidekiq.service | 3 ++- conf/glitchsoc-streaming.service | 3 ++- conf/glitchsoc-web.service | 3 ++- scripts/backup | 5 +++++ scripts/install | 5 +++++ scripts/remove | 3 +++ scripts/restore | 4 ++++ scripts/upgrade | 10 +++++----- 8 files changed, 28 insertions(+), 8 deletions(-) diff --git a/conf/glitchsoc-sidekiq.service b/conf/glitchsoc-sidekiq.service index ff72a14..0c2cfb9 100644 --- a/conf/glitchsoc-sidekiq.service +++ b/conf/glitchsoc-sidekiq.service @@ -13,7 +13,8 @@ Environment="MALLOC_ARENA_MAX=2" ExecStart=__RBENV_ROOT__/versions/__APP__/bin/bundle exec sidekiq -c 25 TimeoutSec=15 Restart=always -StandardError=syslog +StandardOutput=append:/var/log/__APP__/__APP__-sidekiq.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/conf/glitchsoc-streaming.service b/conf/glitchsoc-streaming.service index a5fcfa0..f63945e 100644 --- a/conf/glitchsoc-streaming.service +++ b/conf/glitchsoc-streaming.service @@ -13,7 +13,8 @@ Environment="__YNH_NODE_LOAD_PATH__" ExecStart=__YNH_NODE__ ./streaming TimeoutSec=15 Restart=always -StandardError=syslog +StandardOutput=append:/var/log/__APP__/__APP__-streaming.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/conf/glitchsoc-web.service b/conf/glitchsoc-web.service index 2b615dd..fbfb16b 100644 --- a/conf/glitchsoc-web.service +++ b/conf/glitchsoc-web.service @@ -13,7 +13,8 @@ ExecStart=__RBENV_ROOT__/versions/__APP__/bin/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -SIGUSR1 $MAINPID TimeoutSec=15 Restart=always -StandardError=syslog +StandardOutput=append:/var/log/__APP__/__APP__-web.log +StandardError=inherit # Sandboxing options to harden security # Depending on specificities of your service/app, you may need to tweak these diff --git a/scripts/backup b/scripts/backup index 7df8f50..2cd6afd 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,11 @@ 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 59c9eab..c513e20 100644 --- a/scripts/install +++ b/scripts/install @@ -177,6 +177,11 @@ yunohost service add "$app-streaming" --description="$app streaming service" # Create a cron file ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +# Use logrotate to manage application logfile(s) +mkdir /var/log/$app +chown $app:$app /var/log/$app +ynh_use_logrotate + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/remove b/scripts/remove index 800687d..7df4fda 100644 --- a/scripts/remove +++ b/scripts/remove @@ -48,6 +48,9 @@ ynh_remove_nginx_config # Remove a cron file ynh_secure_remove --file="/etc/cron.d/$app" +# Remote logrotate config +ynh_remove_logrotate + # Remove metapackage and its dependencies ynh_remove_ruby ynh_remove_nodejs diff --git a/scripts/restore b/scripts/restore index c69371b..eba6322 100644 --- a/scripts/restore +++ b/scripts/restore @@ -96,6 +96,10 @@ yunohost service add "$app-streaming" --description="$app streaming service" ynh_restore_file --origin_path="/etc/cron.d/$app" +mkdir -p /var/log/$app +chown -R $app:$app /var/log/$app +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 60c476e..42e5431 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -120,11 +120,6 @@ if [[ $db_name = *'_production' ]]; then ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi -if ynh_compare_current_package_version --comparison lt --version 2023.06.19~ynh2 -then - ynh_remove_logrotate -fi - # If service doesn't exist, create it if [[ -z "$service" ]]; then # Set `service` settings to support `yunohost app shell` command @@ -225,6 +220,11 @@ yunohost service add "$app-streaming" --description="$app streaming service" ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app" +# Use logrotate to manage app-specific logfile(s) +mkdir -p /var/log/$app +chown $app:$app /var/log/$app +ynh_use_logrotate --non-append + #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #=================================================