Add logrotate support, fixes #16 (thanks to monotek!)

Signed-off-by: Christoph Burchert (Chb) <derchb@froxlor.org>
This commit is contained in:
Christoph Burchert (Chb)
2011-09-05 14:56:50 +02:00
parent ca2a8c9907
commit c36a7bf22b
6 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Settings
*
*/
return array(
'groups' => array(
'logrotate' => array(
'title' => $lng['logrotate'],
'fields' => array(
'logrotate_enabled' => array(
'label' => $lng['logrotate_enabled'],
'settinggroup' => 'system',
'varname' => 'logrotate_enabled',
'type' => 'bool',
'default' => false,
'save_method' => 'storeSettingField',
'overview_option' => true
),
'logrotate_binary' => array(
'label' => $lng['logrotate_binary'],
'settinggroup' => 'system',
'varname' => 'logrotate_binary',
'type' => 'string',
'default' => '/usr/sbin/logrotate',
'save_method' => 'storeSettingField',
'overview_option' => false
),
'logrotate_interval' => array(
'label' => $lng['logrotate_interval'],
'settinggroup' => 'system',
'varname' => 'logrotate_interval',
'type' => 'option',
'default' => 'weekly',
'option_mode' => 'one',
'option_options' => array('daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly'),
'save_method' => 'storeSettingField',
'overview_option' => false
),
'logrotate_keep' => array(
'label' => $lng['logrotate_keep'],
'settinggroup' => 'system',
'varname' => 'logrotate_keep',
'type' => 'string',
'default' => '4',
'save_method' => 'storeSettingField',
'overview_option' => false
),
),
),
),
);
?>

View File

@@ -636,6 +636,10 @@ INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('syste
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_repquota_path', '/usr/sbin/repquota'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_repquota_path', '/usr/sbin/repquota');
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_quotatool_path', '/usr/bin/quotatool'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_quotatool_path', '/usr/bin/quotatool');
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_customer_partition', '/dev/root'); INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'diskquota_customer_partition', '/dev/root');
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_enabled', '0');
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_binary', '/usr/sbin/logrotate');
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_interval', 'weekly');
INSERT INTO `panel_settings` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_keep', '4');
# -------------------------------------------------------- # --------------------------------------------------------

View File

@@ -1676,6 +1676,12 @@ if(isFroxlorVersion('0.9.23-rc1'))
showUpdateStep("Updating from 0.9.23-rc1 to 0.9.23"); showUpdateStep("Updating from 0.9.23-rc1 to 0.9.23");
lastStepStatus(0); lastStepStatus(0);
/* add new settings for logrotate - support */
$db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_enabled', '0');");
$db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_binary', '/usr/sbin/logrotate');");
$db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_interval', 'weekly');");
$db->query("INSERT INTO `" . TABLE_PANEL_SETTINGS . "` (`settinggroup`, `varname`, `value`) VALUES ('system', 'logrotate_keep', '4');");
updateToVersion('0.9.23'); updateToVersion('0.9.23');
} }

View File

@@ -1887,3 +1887,10 @@ $lng['serversettings']['diskquota_customer_partition']['description'] = 'Partiti
$lng['tasks']['diskspace_set_quota'] = 'Set quota on filesystem'; $lng['tasks']['diskspace_set_quota'] = 'Set quota on filesystem';
$lng['error']['session_timeout'] = 'Value too low'; $lng['error']['session_timeout'] = 'Value too low';
$lng['error']['session_timeout_desc'] = 'You should not set the session timeout lower than 1 minute.'; $lng['error']['session_timeout_desc'] = 'You should not set the session timeout lower than 1 minute.';
// ADDED IN FROXLOR 0.9.23
$lng['logrotate'] = 'Logrotate';
$lng['logrotate_enabled'] = 'Enable logrotate?';
$lng['logrotate_binary'] = 'Path to logrotate binary:';
$lng['logrotate_interval'] = 'Interval?';
$lng['logrotate_keep'] = 'How many logfiles should be kept?';

View File

@@ -1618,3 +1618,10 @@ $lng['serversettings']['diskquota_customer_partition']['description'] = 'Partiti
$lng['tasks']['diskspace_set_quota'] = 'Quota auf dem Dateisystem setzen'; $lng['tasks']['diskspace_set_quota'] = 'Quota auf dem Dateisystem setzen';
$lng['error']['session_timeout'] = 'Wert zu niedrig'; $lng['error']['session_timeout'] = 'Wert zu niedrig';
$lng['error']['session_timeout_desc'] = 'Der Wert der Session Timeout sollte nicht unter einer Minute liegen.'; $lng['error']['session_timeout_desc'] = 'Der Wert der Session Timeout sollte nicht unter einer Minute liegen.';
// ADDED IN FROXLOR 0.9.23
$lng['logrotate'] = 'Logrotate';
$lng['logrotate_enabled'] = 'Logrotate aktivieren?';
$lng['logrotate_binary'] = 'Pfad zum logrotate binary?';
$lng['logrotate_interval'] = 'Intervall?';
$lng['logrotate_keep'] = 'Wie viele Logdateien sollen aufbewahrt werden?';

View File

@@ -200,6 +200,35 @@ while($row = $db->fetch_array($result))
// make the stuff readable for the customer, #258 // make the stuff readable for the customer, #258
makeChownWithNewStats($row); makeChownWithNewStats($row);
// logrotate
if($settings['system']['logrotate_enabled'] == '1')
{
fwrite($debugHandler, ' logrotate customers logs' . "\n");
$logrotatefile = '/tmp/froxlor_logrotate_tmpfile.conf';
$fh = fopen($logrotatefile, 'w');
$logconf = '# ' . basename($logrotatefile) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" .
$settings['system']['logfiles_directory'] . $row['loginname'] . '-access.log ' .
$settings['system']['logfiles_directory'] . $row['loginname'] . '-error.log {' . "\n" .
$settings['system']['logrotate_interval'] . "\n" .
'missingok' . "\n" .
'rotate ' . $settings['system']['logrotate_keep'] . "\n" .
'compress' . "\n" .
'delaycompress' . "\n" .
'notifempty' . "\n" .
'create' . "\n" .
'}' . "\n";
fwrite($fh, $logconf);
fclose($fh);
safe_exec(escapeshellcmd($settings['system']['logrotate_binary']) . ' ' . $logrotatefile);
fwrite($debugHandler, ' apache::reload: reloading apache' . "\n");
safe_exec(escapeshellcmd($settings['system']['apachereload_command']));
}
/** /**
* Webalizer/AWStats might run for some time, so we'd better check if our database is still present * Webalizer/AWStats might run for some time, so we'd better check if our database is still present
*/ */