From 341ef7175af7c8f21d27262b58da8f5bc2c06ef0 Mon Sep 17 00:00:00 2001 From: Marius Cramer <m.cramer@pixcept.de> Date: Tue, 08 Jul 2014 08:44:59 -0400 Subject: [PATCH] Merge branch 'master_fixes' into 'master' --- server/lib/classes/cron.d/200-logfiles.inc.php | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/lib/classes/cron.d/200-logfiles.inc.php b/server/lib/classes/cron.d/200-logfiles.inc.php index addbf21..a802ff9 100644 --- a/server/lib/classes/cron.d/200-logfiles.inc.php +++ b/server/lib/classes/cron.d/200-logfiles.inc.php @@ -60,7 +60,7 @@ // Manage and compress web logfiles and create traffic statistics //###################################################################################################### - $sql = "SELECT domain_id, domain, type, document_root, web_folder, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') AND server_id = ".$conf['server_id']; + $sql = "SELECT domain_id, domain, type, document_root, web_folder, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') AND server_id = ".$conf['server_id']; $records = $app->db->queryAllRecords($sql); foreach($records as $rec) { @@ -68,7 +68,7 @@ $yesterday = date('Ymd', time() - 86400); $log_folder = 'log'; - if($rec['type'] == 'vhostsubdomain') { + if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') { $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($rec['parent_domain_id'])); $subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']); if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id']; @@ -112,6 +112,30 @@ exec("gzip -c $logfile > $logfile.gz"); unlink($logfile); } + + $cron_logfiles = array('cron.log', 'cron_error.log', 'cron_wget.log'); + foreach($cron_logfiles as $cron_logfile) { + $cron_logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/' . $cron_logfile); + + // rename older files (move up by one) + $num = 7; + while($num >= 1 && is_file($cron_logfile . '.' . $num . '.gz')) { + rename($cron_logfile . '.' . $num . '.gz', $cron_logfile . '.' . ($num + 1) . '.gz'); + $num--; + } + + // compress current logfile + if(is_file($cron_logfile)) { + exec("gzip -c $cron_logfile > $cron_logfile.1.gz"); + exec("cat /dev/null > $cron_logfile"); + } + // remove older logs + $num = 7; + while(is_file($cron_logfile . '.' . $num . '.gz')) { + @unlink($cron_logfile . '.' . $num . '.gz'); + $num++; + } + } // rotate and compress the error.log when it exceeds a size of 10 MB $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/error.log'); -- Gitblit v1.9.1