From b7b150a979c4d5cd5b767987d1467f93024433dd Mon Sep 17 00:00:00 2001 From: chaptergy Date: Tue, 29 Jun 2021 20:40:56 +0200 Subject: [PATCH] Run logrotation binary from program --- backend/setup.js | 22 ++++++++++++++++++- .../etc/logrotate.d/nginx-proxy-manager | 19 +++------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/backend/setup.js b/backend/setup.js index b25ffc0..5e7695d 100644 --- a/backend/setup.js +++ b/backend/setup.js @@ -201,9 +201,29 @@ const setupCertbotPlugins = () => { }); }; + +/** + * Starts a timer to call run the logrotation binary every two days + * @returns {Promise} + */ +const setupLogrotation = () => { + const intervalTimeout = 1000 * 60 * 60 * 24 * 2; // 2 days + + const runLogrotate = async () => { + await utils.exec('logrotate -f /etc/logrotate.d/nginx-proxy-manager'); + logger.info('Logrotate completed.'); + }; + + logger.info('Logrotate Timer initialized'); + setInterval(runLogrotate, intervalTimeout); + // And do this now as well + return runLogrotate(); +}; + module.exports = function () { return setupJwt() .then(setupDefaultUser) .then(setupDefaultSettings) - .then(setupCertbotPlugins); + .then(setupCertbotPlugins) + .then(setupLogrotation); }; diff --git a/docker/rootfs/etc/logrotate.d/nginx-proxy-manager b/docker/rootfs/etc/logrotate.d/nginx-proxy-manager index 5afcaf1..20c23ac 100644 --- a/docker/rootfs/etc/logrotate.d/nginx-proxy-manager +++ b/docker/rootfs/etc/logrotate.d/nginx-proxy-manager @@ -1,4 +1,4 @@ -/data/logs/*_access.log /data/logs/*/*_access.log { +/data/logs/*_access.log /data/logs/*/access.log { create 0644 root root weekly rotate 4 @@ -11,7 +11,7 @@ endscript } -/data/logs/*_error.log /data/logs/*/*_error.log { +/data/logs/*_error.log /data/logs/*/error.log { create 0644 root root weekly rotate 10 @@ -22,17 +22,4 @@ postrotate /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true endscript -} - -/data/logs/*.log /data/logs/*[!_error].log /data/logs/*[!_access].log { - create 0644 root root - weekly - rotate 5 - missingok - notifempty - compress - sharedscripts - postrotate - /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true - endscript -} +} \ No newline at end of file