From f05f984efeecc09ab48d98d89f1198f0d83343e2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Holcroft Date: Wed, 28 Aug 2019 00:09:23 +0200 Subject: [PATCH] improve log files management --- conf/celery-weblate | 6 +++--- conf/celery-weblate.service | 5 ++--- conf/weblate.service | 5 ++--- scripts/install | 6 +++--- scripts/restore | 4 ++-- scripts/upgrade | 11 ++++++++++- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/conf/celery-weblate b/conf/celery-weblate index fc28813..7b2d738 100644 --- a/conf/celery-weblate +++ b/conf/celery-weblate @@ -17,8 +17,8 @@ CELERYD_OPTS="--beat" # - %n will be replaced with the first part of the nodename. # - %I will be replaced with the current child process index # and is important when using the prefork pool to avoid race conditions. -CELERYD_PID_FILE="/var/run/__APP__-celery/weblate-%n.pid" -CELERYD_LOG_FILE="/var/log/__APP__-celery/celery-%n%I.log" +CELERYD_PID_FILE="/var/run/__APP__/weblate-celery-%n.pid" +CELERYD_LOG_FILE="/var/log/__APP__/weblate-celery-%n%I.log" CELERYD_LOG_LEVEL="INFO" -CELERY_WORKER_RUNNING="1" \ No newline at end of file +CELERY_WORKER_RUNNING="1" diff --git a/conf/celery-weblate.service b/conf/celery-weblate.service index a399a1b..a6fe170 100644 --- a/conf/celery-weblate.service +++ b/conf/celery-weblate.service @@ -10,10 +10,9 @@ PermissionsStartOnly=true EnvironmentFile=__FINALPATH__/celery-weblate WorkingDirectory=__FINALPATH__/ # https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory= -RuntimeDirectory=__APP__-celery +RuntimeDirectory=__APP__ -ExecStartPre=/bin/mkdir -p /var/log/__APP__-celery -ExecStartPre=/bin/chown -R __APP__ /var/log/__APP__-celery +ExecStartPre=/bin/chown -R __APP__ /var/log/__APP__ ExecStart=__FINALPATH__/venv/bin/celery multi start ${CELERYD_NODES} \ -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \ diff --git a/conf/weblate.service b/conf/weblate.service index 9b3d597..16e6b43 100644 --- a/conf/weblate.service +++ b/conf/weblate.service @@ -12,14 +12,13 @@ PermissionsStartOnly=true # https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectory= RuntimeDirectory=__APP__ -ExecStartPre=/bin/mkdir -p /var/log/uwsgi/app/__APP__ -ExecStartPre=/bin/chown -R __APP__ /var/log/uwsgi/app/__APP__ +ExecStartPre=/bin/chown -R __APP__ /var/log/__APP__ ExecStart=/usr/bin/uwsgi \ --ini /etc/uwsgi/apps-available/__APP__.ini \ --socket /var/run/__APP__/socket \ --chmod-socket=775 \ - --logto /var/log/uwsgi/app/__APP__/weblate \ + --logto /var/log/__APP__/weblate.log \ --processes 4 diff --git a/scripts/install b/scripts/install index 402c2f4..008a67a 100755 --- a/scripts/install +++ b/scripts/install @@ -306,7 +306,7 @@ chown -R "$app": "$final_path/avatar-cache" ynh_script_progression --message="Configuring log rotation..." --time --weight=1 # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile "/var/log/$app-celery" +ynh_use_logrotate #================================================= # SETUP SSOWAT @@ -334,8 +334,8 @@ fi # ADVERTISE SERVICES IN ADMIN PANEL #================================================= -yunohost service add "$app" --log "/var/log/uwsgi/app/$app/weblate" -yunohost service add "$app-celery" --log "/var/log/$app-celery" +yunohost service add "$app" --log "/var/log/$app/weblate.log" +yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log" #================================================= # Start weblate diff --git a/scripts/restore b/scripts/restore index fe52137..895e5ba 100755 --- a/scripts/restore +++ b/scripts/restore @@ -108,8 +108,8 @@ systemctl enable "$app-celery" #================================================= # Add as a service -yunohost service add "$app" --log "/var/log/uwsgi/app/$app" -yunohost service add "$app-celery" --log "/var/log/$app-celery" +yunohost service add "$app" --log "/var/log/$app/weblate.log" +yunohost service add "$app-celery" --log "/var/log/$app/weblate-celery-w1.log" #================================================= # RESTORE THE CRON FILE diff --git a/scripts/upgrade b/scripts/upgrade index c5a9e9e..0fa5efa 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -165,6 +165,15 @@ then systemctl stop "$app-celery" fi +# (<3.8) log cleanups +if [[ -e "/var/log/uwsgi/app/$app" ]] +then + ynh_systemd_action --service_name="$app" --action="stop" + ynh_systemd_action --service_name="$app-celery" --action="stop" + ynh_secure_remove "/var/log/uwsgi/app/$app" + ynh_secure_remove "/var/log/$app-celery" +fi + #================================================= # CHECK THE PATH #================================================= @@ -403,7 +412,7 @@ ynh_replace_string "__FINALPATH__" "$final_path/" "/etc/cron.d/$app" ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --logfile "/var/log/$app-celery" --non-append +ynh_use_logrotate #================================================= # GENERIC FINALIZATION