Skip to content

Commit 641cb3b

Browse files
author
redray
committed
cron errors got to logfile now and are available in monitor-section
1 parent 70cc7d0 commit 641cb3b

File tree

6 files changed

+64
-6
lines changed

6 files changed

+64
-6
lines changed

install/lib/installer_base.lib.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,9 +1042,12 @@ public function install_crontab()
10421042
if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
10431043
}
10441044

1045+
// Crontab must end with an empty line or comment!
10451046
$root_cron_jobs = array(
1046-
'* * * * * /usr/local/ispconfig/server/server.sh > /dev/null',
1047-
'30 00 * * * /usr/local/ispconfig/server/cron_daily.sh > /dev/null'
1047+
'# --- ISPConfig ----',
1048+
'* * * * * /usr/local/ispconfig/server/server.sh > /dev/null 2>> /var/log/var/log/ispconfig/cron.log',
1049+
'30 00 * * * /usr/local/ispconfig/server/cron_daily.sh > /dev/null 2>> /var/log/var/log/ispconfig/cron.log',
1050+
'# ------------------'
10481051
);
10491052
foreach($root_cron_jobs as $cron_job) {
10501053
if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
@@ -1061,7 +1064,12 @@ public function install_crontab()
10611064
exec('crontab -u getmail -l > crontab.txt');
10621065
$existing_cron_jobs = file('crontab.txt');
10631066

1064-
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf > /dev/null');
1067+
// Crontab must end with an empty line or comment!
1068+
$cron_jobs = array(
1069+
'# --- ISPConfig ----',
1070+
'*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf > /dev/null 2>> /var/log/var/log/ispconfig/cron.log',
1071+
'# ------------------'
1072+
);
10651073

10661074
// remove existing ispconfig cronjobs, in case the syntax has changed
10671075
foreach($cron_jobs as $key => $val) {

interface/web/monitor/lib/lang/en.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ $wb['Show Mail-Log'] = 'Show Mail-Log';
3535
$wb['Show Mail warn-Log'] = 'Show Mail warn-Log';
3636
$wb['Show Mail err-Log'] = 'Show Mail err-Log';
3737
$wb['Show System-Log'] = 'Show System-Log';
38+
$wb['Show ISPC Cron-Log'] = 'Show ISPC Cron-Log';
3839
$wb['Show Freshclam-Log'] = 'Show Freshclam-Log';
3940
$wb['Show Clamav-Log'] = 'Show Clamav-Log';
4041
$wb['Show ISPConfig-Log'] = 'Show ISPConfig-Log';

interface/web/monitor/lib/module.conf.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
'target' => 'content',
135135
'link' => 'monitor/show_log.php?log=log_messages');
136136

137+
$items[] = array( 'title' => "Show ISPC Cron-Log",
138+
'target' => 'content',
139+
'link' => 'monitor/show_log.php?log=log_ispc_cron');
140+
137141
$items[] = array( 'title' => "Show Freshclam-Log",
138142
'target' => 'content',
139143
'link' => 'monitor/show_log.php?log=log_freshclam');

interface/web/monitor/show_log.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
$logId = 'log_messages';
6565
$title = 'System (Server: ' . $_SESSION['monitor']['server_name'] . ')';
6666
break;
67+
case 'log_ispc_cron':
68+
$logId = 'log_ispc_cron';
69+
$title = 'System (Server: ' . $_SESSION['monitor']['server_name'] . ')';
70+
break;
6771
case 'log_freshclam':
6872
$logId = 'log_freshclam';
6973
$title = 'Freshclam - Log (Server: ' . $_SESSION['monitor']['server_name'] . ')';

server/cron_daily.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
9292
$records = $app->db->queryAllRecords($sql);
9393
foreach($records as $rec) {
94-
$yesterday = date("mdY",time() - 86400);
94+
$yesterday = date("Ymd",time() - 86400);
9595
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log');
9696
if(@is_file($logfile)) {
9797
$domain = escapeshellcmd($rec["domain"]);
@@ -110,15 +110,15 @@
110110
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
111111
$records = $app->db->queryAllRecords($sql);
112112
foreach($records as $rec) {
113-
$yesterday = date("mdY",time() - 86400);
113+
$yesterday = date("Ymd",time() - 86400);
114114
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log');
115115
if(@is_file($logfile)) {
116116
// Compress yesterdays logfile
117117
exec("gzip -c $logfile > $logfile.gz");
118118
}
119119

120120
// delete logfiles after 30 days
121-
$month_ago = date("mdY",time() - 86400 * 30);
121+
$month_ago = date("Ymd",time() - 86400 * 30);
122122
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log.gz');
123123
if(@is_file($logfile)) {
124124
unlink($logfile);

server/mods-available/monitor_core_module.inc.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ function doMonitor()
113113
$this->monitorMailWarnLog();
114114
$this->monitorMailErrLog();
115115
$this->monitorMessagesLog();
116+
$this->monitorISPCCronLog();
116117
$this->monitorFreshClamLog();
117118
$this->monitorClamAvLog();
118119
$this->monitorIspConfigLog();
@@ -937,6 +938,43 @@ function monitorMessagesLog()
937938
$this->_delOldRecords($type, 10);
938939
}
939940

941+
function monitorISPCCronLog()
942+
{
943+
global $app;
944+
global $conf;
945+
946+
/* the id of the server as int */
947+
$server_id = intval($conf["server_id"]);
948+
949+
/** The type of the data */
950+
$type = 'log_ispc_cron';
951+
952+
/* Get the data of the log */
953+
$data = $this->_getLogData($type);
954+
955+
/*
956+
* actually this info has no state.
957+
* maybe someone knows better...???...
958+
*/
959+
$state = 'no_state';
960+
961+
/*
962+
Insert the data into the database
963+
*/
964+
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
965+
"VALUES (".
966+
$server_id . ", " .
967+
"'" . $app->dbmaster->quote($type) . "', " .
968+
time() . ", " .
969+
"'" . $app->dbmaster->quote(serialize($data)) . "', " .
970+
"'" . $state . "'" .
971+
")";
972+
$app->dbmaster->query($sql);
973+
974+
/* The new data is written, now we can delete the old one */
975+
$this->_delOldRecords($type, 10);
976+
}
977+
940978
function monitorFreshClamLog()
941979
{
942980
global $app;
@@ -1092,6 +1130,9 @@ function _getLogData($log){
10921130
case 'log_messages':
10931131
$logfile = '/var/log/messages';
10941132
break;
1133+
case 'log_ispc_cron':
1134+
$logfile = '/var/log/ispconfig/cron.log';
1135+
break;
10951136
case 'log_freshclam':
10961137
$logfile = '/var/log/clamav/freshclam.log';
10971138
break;

0 commit comments

Comments
 (0)