Marius Cramer
2014-02-18 46236c96277327a03828d3fa2f26d694cfb36cc1
Implemented: FS#3347 - Add output logging of cronjobs
1 files added
6 files modified
34 ■■■■■ changed files
install/sql/incremental/upd_0069.sql 1 ●●●● patch | view | raw | blame | history
install/sql/ispconfig3.sql 1 ●●●● patch | view | raw | blame | history
interface/web/sites/form/cron.tform.php 6 ●●●●● patch | view | raw | blame | history
interface/web/sites/lib/lang/de_cron.lng 1 ●●●● patch | view | raw | blame | history
interface/web/sites/lib/lang/en_cron.lng 1 ●●●● patch | view | raw | blame | history
interface/web/sites/templates/cron_edit.htm 6 ●●●●● patch | view | raw | blame | history
server/plugins-available/cron_plugin.inc.php 18 ●●●● patch | view | raw | blame | history
install/sql/incremental/upd_0069.sql
New file
@@ -0,0 +1 @@
ALTER TABLE `cron` ADD `log` enum('n','y') NOT NULL default 'n' AFTER `run_wday`;
install/sql/ispconfig3.sql
@@ -402,6 +402,7 @@
  `run_mday` varchar(100) NULL,
  `run_month` varchar(100) NULL,
  `run_wday` varchar(100) NULL,
  `log` enum('n','y') NOT NULL default 'n',
  `active` enum('n','y') NOT NULL default 'y',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
interface/web/sites/form/cron.tform.php
@@ -172,6 +172,12 @@
            'valuelimit' => 'list:url,full,chrooted',
            'value'     => array('url' => 'Url', 'full' => 'Full', 'chrooted' => 'Chrooted')
        ),
        'log' => array (
            'datatype' => 'VARCHAR',
            'formtype' => 'CHECKBOX',
            'default' => 'n',
            'value'  => array(0 => 'n', 1 => 'y')
        ),
        'active' => array (
            'datatype' => 'VARCHAR',
            'formtype' => 'CHECKBOX',
interface/web/sites/lib/lang/de_cron.lng
@@ -20,4 +20,5 @@
$wb['unknown_fieldtype_error'] = 'Es wurde ein unbekanntes Feld verwendet.';
$wb['server_id_error_empty'] = 'Die Server-ID ist leer.';
$wb['command_hint_txt'] = 'z. B. /var/www/clients/clientX/webY/myscript.sh oder http://www.mydomain.com/path/script.php. Der Platzhalter [web_root] wird durch /var/www/clients/clientX/webY/web ersetzt.';
$wb['log_output_txt'] = 'Ausgabe loggen';
?>
interface/web/sites/lib/lang/en_cron.lng
@@ -20,4 +20,5 @@
$wb['unknown_fieldtype_error'] = 'An unknown field type has been used.';
$wb['server_id_error_empty'] = 'The server ID is empty.';
$wb['command_hint_txt'] = 'e.g. /var/www/clients/clientX/webY/myscript.sh or http://www.mydomain.com/path/script.php, you can use [web_root] placeholder that is replaced by /var/www/clients/clientX/webY/web.';
$wb['log_output_txt'] = 'Log output';
?>
interface/web/sites/templates/cron_edit.htm
@@ -50,6 +50,12 @@
                <p class="formHint">{tmpl_var name='command_hint_txt'}</p>
            </div>
            <div class="ctrlHolder">
                <p class="label">{tmpl_var name='log_output_txt'}</p>
                <div class="multiField">
                    {tmpl_var name='log'}
                </div>
            </div>
            <div class="ctrlHolder">
                <p class="label">{tmpl_var name='active_txt'}</p>
                <div class="multiField">
                    {tmpl_var name='active'}
server/plugins-available/cron_plugin.inc.php
@@ -193,7 +193,7 @@
        $chr_cmd_count = 0;
        //* read all active cron jobs from database and write them to file
        $cron_jobs = $app->db->queryAllRecords("SELECT c.`run_min`, c.`run_hour`, c.`run_mday`, c.`run_month`, c.`run_wday`, c.`command`, c.`type`, `web_domain`.`domain` as `domain` FROM `cron` as c INNER JOIN `web_domain` ON `web_domain`.`domain_id` = c.`parent_domain_id` WHERE c.`parent_domain_id` = ".intval($this->parent_domain["domain_id"]) . " AND c.`active` = 'y'");
        $cron_jobs = $app->db->queryAllRecords("SELECT c.`run_min`, c.`run_hour`, c.`run_mday`, c.`run_month`, c.`run_wday`, c.`command`, c.`type`, c.`log`, `web_domain`.`domain` as `domain` FROM `cron` as c INNER JOIN `web_domain` ON `web_domain`.`domain_id` = c.`parent_domain_id` WHERE c.`parent_domain_id` = ".intval($this->parent_domain["domain_id"]) . " AND c.`active` = 'y'");
        if($cron_jobs && count($cron_jobs) > 0) {
            foreach($cron_jobs as $job) {
                if($job['run_month'] == '@reboot') {
@@ -201,9 +201,18 @@
                } else {
                    $command = str_replace(" ", "", $job['run_min']) . "\t" . str_replace(" ", "", $job['run_hour']) . "\t" . str_replace(" ", "", $job['run_mday']) . "\t" . str_replace(" ", "", $job['run_month']) . "\t" . str_replace(" ", "", $job['run_wday']);
                }
                $log_target = ">/dev/null 2>&1";
                if($job['log'] == 'y') {
                    $log_root = '';
                    if($job['type'] != 'chrooted') $log_root = $this->parent_domain['document_root'] . '/log';
                    $log_target = '>' . $log_root . '/cron.log 2>' . $log_root . '/cron_error.log';
                }
                $command .= "\t{$this->parent_domain['system_user']}"; //* running as user
                if($job['type'] == 'url') {
                    $command .= "\t{$cron_config['wget']} -q -t 1 -T 7200 -O /dev/null " . escapeshellarg($job['command']) . " >/dev/null 2>&1";
                    $command .= "\t{$cron_config['wget']} -q -t 1 -T 7200 -O /dev/null " . escapeshellarg($job['command']) . " " . $log_target;
                } else {
                    $web_root = '';
                    if($job['type'] == 'chrooted') {
@@ -214,12 +223,15 @@
                    } else {
                        $web_root = $this->parent_domain['document_root'];
                    }
                    $log_root = $web_root . '/';
                    $web_root .= '/web';
                    $job['command'] = str_replace('[web_root]', $web_root, $job['command']);
                    $command .= "\t";
                    if($job['type'] != 'chrooted' && substr($job['command'], 0, 1) != "/") $command .= $this->parent_domain['document_root'].'/';
                    $command .= $job['command'];
                    $command .= $job['command'] . " " . $log_target;
                }
                if($job['type'] == 'chrooted') {