PDA

View Full Version : Error.log rotation


Alex1
14th July 2009, 09:31
Hello

can you add the rotation of vhosts' error.log in the next version? sometimes it can be very big causing problems in user's quota.

Bookworm
29th August 2009, 16:29
It looks like what could be done, at least as a quick and dirty fix, is modify the /usr/local/ispconfig/server/cron_daily.php file as follows.

Take the logrotation section and duplicate the access log entries with error log entries.

################################################## ################################################## ###
// Manage and compress web logfiles
################################################## ################################################## ###

$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
$records = $app->db->queryAllRecords($sql);
foreach($records as $rec) {
$yesterday = date("Ymd",time() - 86400);
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log');
$errorfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-error.log');
if(@is_file($logfile)) {
// Compress yesterdays logfile
exec("gzip -c $logfile > $logfile.gz");
unlink($logfile);
}
if(@is_file($errorfile)) {
// Compress yesterdays logfile
exec("gzip -c $errorfile > $errorfile.gz");
unlink($errorfile);
}

// delete logfiles after 7 days
$week_ago = date("Ymd",time() - 86400 * 7);
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$week_ago.'-access.log.gz');
$errorfile = escapeshellcmd($rec["document_root"].'/log/'.$week_ago.'-error.log.gz');
if(@is_file($logfile)) {
unlink($logfile);
}
if(@is_file($errorfile)) {
unlink($errorfile);
}
}

#####

I haven't tried it yet - I just put it in myself - but it should work fine.