Skip to content

Commit 3dfecb0

Browse files
author
Till Brehm
committed
Merge branch 'stable-3.1' into 'stable-3.1'
Stable 3.1 See merge request ispconfig/ispconfig3!783
2 parents caeab8c + fe8ea3f commit 3dfecb0

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

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

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,18 @@ public function onRunJob() {
137137
}
138138
}
139139

140-
// rotate and compress the error.log when it exceeds a size of 10 MB
141-
$logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/error.log');
142-
if(is_file($logfile) && filesize($logfile) > 10000000) {
143-
exec("gzip -c $logfile > $logfile.1.gz");
144-
exec("cat /dev/null > $logfile");
140+
// rotate and compress the error.log
141+
$error_logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/error.log');
142+
// rename older files (move up by one)
143+
$num = $log_retention;
144+
while($num >= 1 && is_file($error_logfile . '.' . $num . '.gz')) {
145+
rename($error_logfile . '.' . $num . '.gz', $error_logfile . '.' . ($num + 1) . '.gz');
146+
$num--;
147+
}
148+
// compress current logfile
149+
if(is_file($error_logfile)) {
150+
exec("gzip -c $error_logfile > $error_logfile.1.gz");
151+
exec("cat /dev/null > $error_logfile");
145152
}
146153

147154
// delete logfiles after x days (default 30)
@@ -168,25 +175,26 @@ public function onRunJob() {
168175
// Rotate the ispconfig.log file
169176
//######################################################################################################
170177

171-
// rotate the ispconfig.log when it exceeds a size of 10 MB
172-
$logfile = $conf['ispconfig_log_dir'].'/ispconfig.log';
173-
if(is_file($logfile) && filesize($logfile) > 10000000) {
174-
exec("gzip -c $logfile > $logfile.1.gz");
175-
exec("cat /dev/null > $logfile");
176-
}
177-
178-
// rotate the cron.log when it exceeds a size of 10 MB
179-
$logfile = $conf['ispconfig_log_dir'].'/cron.log';
180-
if(is_file($logfile) && filesize($logfile) > 10000000) {
181-
exec("gzip -c $logfile > $logfile.1.gz");
182-
exec("cat /dev/null > $logfile");
183-
}
178+
$num = 10;
184179

185-
// rotate the auth.log when it exceeds a size of 10 MB
186-
$logfile = $conf['ispconfig_log_dir'].'/auth.log';
187-
if(is_file($logfile) && filesize($logfile) > 10000000) {
188-
exec("gzip -c $logfile > $logfile.1.gz");
189-
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+
}
190198
}
191199

192200
//######################################################################################################

0 commit comments

Comments
 (0)