Skip to content

Commit b7b150a

Browse files
committed
Run logrotation binary from program
1 parent fae848b commit b7b150a

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

backend/setup.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,29 @@ const setupCertbotPlugins = () => {
201201
});
202202
};
203203

204+
205+
/**
206+
* Starts a timer to call run the logrotation binary every two days
207+
* @returns {Promise}
208+
*/
209+
const setupLogrotation = () => {
210+
const intervalTimeout = 1000 * 60 * 60 * 24 * 2; // 2 days
211+
212+
const runLogrotate = async () => {
213+
await utils.exec('logrotate -f /etc/logrotate.d/nginx-proxy-manager');
214+
logger.info('Logrotate completed.');
215+
};
216+
217+
logger.info('Logrotate Timer initialized');
218+
setInterval(runLogrotate, intervalTimeout);
219+
// And do this now as well
220+
return runLogrotate();
221+
};
222+
204223
module.exports = function () {
205224
return setupJwt()
206225
.then(setupDefaultUser)
207226
.then(setupDefaultSettings)
208-
.then(setupCertbotPlugins);
227+
.then(setupCertbotPlugins)
228+
.then(setupLogrotation);
209229
};
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/data/logs/*_access.log /data/logs/*/*_access.log {
1+
/data/logs/*_access.log /data/logs/*/access.log {
22
create 0644 root root
33
weekly
44
rotate 4
@@ -11,7 +11,7 @@
1111
endscript
1212
}
1313

14-
/data/logs/*_error.log /data/logs/*/*_error.log {
14+
/data/logs/*_error.log /data/logs/*/error.log {
1515
create 0644 root root
1616
weekly
1717
rotate 10
@@ -22,17 +22,4 @@
2222
postrotate
2323
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
2424
endscript
25-
}
26-
27-
/data/logs/*.log /data/logs/*[!_error].log /data/logs/*[!_access].log {
28-
create 0644 root root
29-
weekly
30-
rotate 5
31-
missingok
32-
notifempty
33-
compress
34-
sharedscripts
35-
postrotate
36-
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
37-
endscript
38-
}
25+
}

0 commit comments

Comments
 (0)