Skip to content

Commit 46236c9

Browse files
author
Marius Cramer
committed
Implemented: FS#3347 - Add output logging of cronjobs
1 parent 0a02ee3 commit 46236c9

File tree

7 files changed

+31
-3
lines changed

7 files changed

+31
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `cron` ADD `log` enum('n','y') NOT NULL default 'n' AFTER `run_wday`;

install/sql/ispconfig3.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ CREATE TABLE `cron` (
402402
`run_mday` varchar(100) NULL,
403403
`run_month` varchar(100) NULL,
404404
`run_wday` varchar(100) NULL,
405+
`log` enum('n','y') NOT NULL default 'n',
405406
`active` enum('n','y') NOT NULL default 'y',
406407
PRIMARY KEY (`id`)
407408
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

interface/web/sites/form/cron.tform.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@
172172
'valuelimit' => 'list:url,full,chrooted',
173173
'value' => array('url' => 'Url', 'full' => 'Full', 'chrooted' => 'Chrooted')
174174
),
175+
'log' => array (
176+
'datatype' => 'VARCHAR',
177+
'formtype' => 'CHECKBOX',
178+
'default' => 'n',
179+
'value' => array(0 => 'n', 1 => 'y')
180+
),
175181
'active' => array (
176182
'datatype' => 'VARCHAR',
177183
'formtype' => 'CHECKBOX',

interface/web/sites/lib/lang/de_cron.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ $wb['command_error_format'] = 'Das Format für den Befehl ist nicht korrekt. Bea
2020
$wb['unknown_fieldtype_error'] = 'Es wurde ein unbekanntes Feld verwendet.';
2121
$wb['server_id_error_empty'] = 'Die Server-ID ist leer.';
2222
$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.';
23+
$wb['log_output_txt'] = 'Ausgabe loggen';
2324
?>

interface/web/sites/lib/lang/en_cron.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ $wb['command_error_format'] = 'Invalid command format. Please note that in case
2020
$wb['unknown_fieldtype_error'] = 'An unknown field type has been used.';
2121
$wb['server_id_error_empty'] = 'The server ID is empty.';
2222
$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.';
23+
$wb['log_output_txt'] = 'Log output';
2324
?>

interface/web/sites/templates/cron_edit.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ <h2><tmpl_var name="list_head_txt"></h2>
4949
<input name="command" id="command" value="{tmpl_var name='command'}" size="30" maxlength="255" type="text" class="textInput" />
5050
<p class="formHint">{tmpl_var name='command_hint_txt'}</p>
5151
</div>
52+
<div class="ctrlHolder">
53+
<p class="label">{tmpl_var name='log_output_txt'}</p>
54+
<div class="multiField">
55+
{tmpl_var name='log'}
56+
</div>
57+
</div>
5258
<div class="ctrlHolder">
5359
<p class="label">{tmpl_var name='active_txt'}</p>
5460
<div class="multiField">

server/plugins-available/cron_plugin.inc.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,26 @@ function _write_crontab() {
193193
$chr_cmd_count = 0;
194194

195195
//* read all active cron jobs from database and write them to file
196-
$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'");
196+
$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'");
197197
if($cron_jobs && count($cron_jobs) > 0) {
198198
foreach($cron_jobs as $job) {
199199
if($job['run_month'] == '@reboot') {
200200
$command = "@reboot";
201201
} else {
202202
$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']);
203203
}
204+
205+
$log_target = ">/dev/null 2>&1";
206+
if($job['log'] == 'y') {
207+
$log_root = '';
208+
if($job['type'] != 'chrooted') $log_root = $this->parent_domain['document_root'] . '/log';
209+
210+
$log_target = '>' . $log_root . '/cron.log 2>' . $log_root . '/cron_error.log';
211+
}
212+
204213
$command .= "\t{$this->parent_domain['system_user']}"; //* running as user
205214
if($job['type'] == 'url') {
206-
$command .= "\t{$cron_config['wget']} -q -t 1 -T 7200 -O /dev/null " . escapeshellarg($job['command']) . " >/dev/null 2>&1";
215+
$command .= "\t{$cron_config['wget']} -q -t 1 -T 7200 -O /dev/null " . escapeshellarg($job['command']) . " " . $log_target;
207216
} else {
208217
$web_root = '';
209218
if($job['type'] == 'chrooted') {
@@ -214,12 +223,15 @@ function _write_crontab() {
214223
} else {
215224
$web_root = $this->parent_domain['document_root'];
216225
}
226+
227+
$log_root = $web_root . '/';
228+
217229
$web_root .= '/web';
218230
$job['command'] = str_replace('[web_root]', $web_root, $job['command']);
219231

220232
$command .= "\t";
221233
if($job['type'] != 'chrooted' && substr($job['command'], 0, 1) != "/") $command .= $this->parent_domain['document_root'].'/';
222-
$command .= $job['command'];
234+
$command .= $job['command'] . " " . $log_target;
223235
}
224236

225237
if($job['type'] == 'chrooted') {

0 commit comments

Comments
 (0)