time() - 86400) { // 86400 seconds = 1 day if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - The cron lock file is older than one day.' . "\n"; exit; } // Check if the process id we have in the lock file is still present $pid = trim(file_get_contents($lockFile)); if(preg_match('/^[0-9]+$/', $pid)) { if(file_exists('/proc/' . $pid)) { if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already an instance of cron.php running with pid ' . $pid . '.' . "\n"; exit; } } if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n"; } // Set Lockfile @file_put_contents($lockFile, getmypid()); if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n"; require SCRIPT_PATH."/lib/app.inc.php"; set_time_limit(0); ini_set('error_reporting', E_ALL & ~E_NOTICE); // make sure server_id is always an int $conf['server_id'] = intval($conf['server_id']); // Load required base-classes $app->uses('ini_parser,file,services,getconf,system,cron,functions'); $app->load('libdatetime,cronjob'); // read all cron jobs $path = SCRIPT_PATH . '/lib/classes/cron.d'; if(!is_dir($path)) die('Cron path missing!'); $files = array(); $d = opendir($path); while($f = readdir($d)) { $file_path = $path . '/' . $f; if($f === '.' || $f === '..' || !is_file($file_path)) continue; if(substr($f, strrpos($f, '.')) !== '.php') continue; $files[] = $f; } closedir($d); // sort in alphabetical order, so we can use prefixes like 000-xxx sort($files); foreach($files as $f) { $name = substr($f, 0, strpos($f, '.')); if(preg_match('/^\d+\-(.*)$/', $name, $match)) $name = $match[1]; // strip numerical prefix from file name include $path . '/' . $f; $class_name = 'cronjob_' . $name; if(class_exists($class_name, false)) { $cronjob = new $class_name(); if(get_parent_class($cronjob) !== 'cronjob') { if($conf['log_priority'] <= LOGLEVEL_WARN) print 'Invalid class ' . $class_name . ' not extending class cronjob (' . get_parent_class($cronjob) . ')!' . "\n"; unset($cronjob); continue; } if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Included ' . $class_name . ' from ' . $path . '/' . $f . ' -> will now run job.' . "\n"; $cronjob->run(); if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'run job (' . $class_name . ') done.' . "\n"; unset($cronjob); } } unset($files); // Remove lock @unlink($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'); $app->log('Remove Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', LOGLEVEL_DEBUG); if($conf['log_priority'] <= LOGLEVEL_DEBUG) die("finished.\n"); ?>