From 4075251cb55657437a76eceb28a581d179dd69f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Tue, 6 Sep 2022 18:04:07 +0200 Subject: [PATCH] logrotate + log in /var/log/usershub/usershub.log --- docs/changelog.rst | 5 +++++ install_app.sh | 5 +++++ log_rotate | 6 +++++- tmpfiles-usershub.conf | 2 ++ usershub.service | 6 +++--- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tmpfiles-usershub.conf diff --git a/docs/changelog.rst b/docs/changelog.rst index 9864551..2ed7fa1 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -13,6 +13,11 @@ CHANGELOG * *systemd* : Ajout d’une dépendance au service ``postgresql`` * Amélioration de l’affichage des tables +* Fichiers de log : + + * Les logs sont à présent écrits dans le fichier ``/var/log/usershub/usershub.log`` + * L’outil ``logrotate`` est configuré pour assurer la rotation du fichier + * L’ancien fichier de log ``/var/log/usershub.log`` est intouché; vous pouvez le supprimer, ou l’archiver manuellement. **🐛 Corrections** diff --git a/install_app.sh b/install_app.sh index 1c34568..b0fdee9 100755 --- a/install_app.sh +++ b/install_app.sh @@ -54,9 +54,14 @@ cd ../.. export USERSHUB_DIR=$(readlink -e "${0%/*}") # Configuration systemd +envsubst '${USER}' < tmpfiles-usershub.conf | sudo tee /etc/tmpfiles.d/usershub.conf || exit 1 +sudo systemd-tmpfiles --create /etc/tmpfiles.d/usershub.conf || exit 1 envsubst '${USER} ${USERSHUB_DIR}' < usershub.service | sudo tee /etc/systemd/system/usershub.service || exit 1 sudo systemctl daemon-reload || exit 1 +# Configuration logrotate +envsubst '${USER}' < log_rotate | sudo tee /etc/logrotate.d/usershub + # Configuration apache sudo cp usershub_apache.conf /etc/apache2/conf-available/usershub.conf || exit 1 sudo a2enmod proxy || exit 1 diff --git a/log_rotate b/log_rotate index 61af3c9..37ea7f5 100644 --- a/log_rotate +++ b/log_rotate @@ -1,7 +1,11 @@ -/var/log/usershub.log { +/var/log/usershub/usershub.log { + su ${USER} ${USER} daily rotate 8 size 100M create compress + postrotate + systemctl reload usershub || true + endscript } diff --git a/tmpfiles-usershub.conf b/tmpfiles-usershub.conf new file mode 100644 index 0000000..56b5b65 --- /dev/null +++ b/tmpfiles-usershub.conf @@ -0,0 +1,2 @@ +d /run/usershb 0750 ${USER} ${USER} - +d /var/log/usershub 0750 ${USER} ${USER} - diff --git a/usershub.service b/usershub.service index 03801c0..8281629 100644 --- a/usershub.service +++ b/usershub.service @@ -14,16 +14,16 @@ Environment=GUNICORN_NUM_WORKERS=4 Environment=GUNICORN_HOST=127.0.0.1 Environment=GUNICORN_PORT=5001 Environment=GUNICORN_TIMEOUT=30 +Environment=GUNICORN_LOG_FILE=/var/log/usershub/%N%I.log EnvironmentFile=-${USERSHUB_DIR}/environ ExecStart=${USERSHUB_DIR}/venv/bin/gunicorn app.app:create_app() \ --name "${GUNICORN_PROC_NAME}" --workers "${GUNICORN_NUM_WORKERS}" \ - --bind "${GUNICORN_HOST}:${GUNICORN_PORT}" --timeout="${GUNICORN_TIMEOUT}" + --bind "${GUNICORN_HOST}:${GUNICORN_PORT}" --timeout="${GUNICORN_TIMEOUT}" \ + --log-file "${GUNICORN_LOG_FILE}" ExecReload=/bin/kill -s HUP $MAINPID TimeoutStartSec=10 TimeoutStopSec=5 PrivateTmp=true -StandardOutput=append:/var/log/usershub.log -StandardError=inherit [Install] WantedBy=multi-user.target