Skip to content

Commit fe8ea3f

Browse files
author
florian030
committed
daily rotate for ispconfig-logs (ispconfig.log, cron.log, auth.log) up to 10 days
1 parent ed1073f commit fe8ea3f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

server/lib/classes/cron.d/200-logfiles.inc.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,26 @@ public function onRunJob() {
175175
// Rotate the ispconfig.log file
176176
//######################################################################################################
177177

178-
// rotate the ispconfig.log when it exceeds a size of 10 MB
179-
$logfile = $conf['ispconfig_log_dir'].'/ispconfig.log';
180-
if(is_file($logfile) && filesize($logfile) > 10000000) {
181-
exec("gzip -c $logfile > $logfile.1.gz");
182-
exec("cat /dev/null > $logfile");
183-
}
184-
185-
// rotate the cron.log when it exceeds a size of 10 MB
186-
$logfile = $conf['ispconfig_log_dir'].'/cron.log';
187-
if(is_file($logfile) && filesize($logfile) > 10000000) {
188-
exec("gzip -c $logfile > $logfile.1.gz");
189-
exec("cat /dev/null > $logfile");
190-
}
178+
$num = 10;
191179

192-
// rotate the auth.log when it exceeds a size of 10 MB
193-
$logfile = $conf['ispconfig_log_dir'].'/auth.log';
194-
if(is_file($logfile) && filesize($logfile) > 10000000) {
195-
exec("gzip -c $logfile > $logfile.1.gz");
196-
exec("cat /dev/null > $logfile");
180+
$ispconfig_logfiles = array('ispconfig.log', 'cron.log', 'auth.log');
181+
foreach($ispconfig_logfiles as $ispconfig_logfile) {
182+
$ispconfig_logfile = escapeshellcmd($conf['ispconfig_log_dir'].'/'.$ispconfig_logfile);
183+
// rename older files (move up by one)
184+
while($num >= 1 && is_file($ispconfig_logfile . '.' . $num . '.gz')) {
185+
rename($ispconfig_logfile . '.' . $num . '.gz', $ispconfig_logfile . '.' . ($num + 1) . '.gz');
186+
$num--;
187+
}
188+
// compress current logfile
189+
if(is_file($ispconfig_logfile)) {
190+
exec("gzip -c $ispconfig_logfile > $ispconfig_logfile.1.gz");
191+
exec("cat /dev/null > $ispconfig_logfile");
192+
}
193+
// remove older logs
194+
while(is_file($ispconfig_logfile . '.' . $num . '.gz')) {
195+
@unlink($ispconfig_logfile . '.' . $num . '.gz');
196+
$num++;
197+
}
197198
}
198199

199200
//######################################################################################################

0 commit comments

Comments
 (0)