commit | author | age
|
5de2af
|
1 |
<?php |
M |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007-2012, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"])); |
b1a6a5
|
32 |
require SCRIPT_PATH."/lib/config.inc.php"; |
611407
|
33 |
|
MB |
34 |
// Check whether another instance of this script is already running |
|
35 |
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) { |
|
36 |
clearstatcache(); |
|
37 |
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')); |
|
38 |
if(preg_match('/^[0-9]+$/', $pid)) { |
|
39 |
if(file_exists('/proc/' . $pid)) { |
|
40 |
print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n"; |
|
41 |
exit; |
|
42 |
} |
|
43 |
} |
|
44 |
print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n"; |
|
45 |
} |
|
46 |
|
|
47 |
// Set Lockfile |
|
48 |
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', getmypid()); |
|
49 |
|
|
50 |
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n"; |
|
51 |
|
|
52 |
|
b1a6a5
|
53 |
require SCRIPT_PATH."/lib/app.inc.php"; |
5de2af
|
54 |
|
M |
55 |
set_time_limit(0); |
|
56 |
ini_set('error_reporting', E_ALL & ~E_NOTICE); |
|
57 |
|
|
58 |
// make sure server_id is always an int |
|
59 |
$conf['server_id'] = intval($conf['server_id']); |
|
60 |
|
|
61 |
|
|
62 |
// Load required base-classes |
|
63 |
$app->uses('ini_parser,file,services,getconf,system,cron,functions'); |
|
64 |
$app->load('libdatetime,cronjob'); |
|
65 |
|
|
66 |
|
|
67 |
// read all cron jobs |
|
68 |
$path = SCRIPT_PATH . '/lib/classes/cron.d'; |
|
69 |
if(!is_dir($path)) die('Cron path missing!'); |
|
70 |
$files = array(); |
|
71 |
$d = opendir($path); |
|
72 |
while($f = readdir($d)) { |
b1a6a5
|
73 |
$file_path = $path . '/' . $f; |
MC |
74 |
if($f === '.' || $f === '..' || !is_file($file_path)) continue; |
|
75 |
if(substr($f, strrpos($f, '.')) !== '.php') continue; |
|
76 |
$files[] = $f; |
5de2af
|
77 |
} |
M |
78 |
closedir($d); |
|
79 |
|
|
80 |
// sort in alphabetical order, so we can use prefixes like 000-xxx |
|
81 |
sort($files); |
b1a6a5
|
82 |
|
5de2af
|
83 |
foreach($files as $f) { |
b1a6a5
|
84 |
$name = substr($f, 0, strpos($f, '.')); |
MC |
85 |
if(preg_match('/^\d+\-(.*)$/', $name, $match)) $name = $match[1]; // strip numerical prefix from file name |
|
86 |
|
|
87 |
include $path . '/' . $f; |
|
88 |
$class_name = 'cronjob_' . $name; |
|
89 |
|
|
90 |
if(class_exists($class_name, false)) { |
|
91 |
$cronjob = new $class_name(); |
|
92 |
if(get_parent_class($cronjob) !== 'cronjob') { |
|
93 |
print 'Invalid class ' . $class_name . ' not extending class cronjob (' . get_parent_class($cronjob) . ')!' . "\n"; |
|
94 |
unset($cronjob); |
|
95 |
continue; |
|
96 |
} |
e956ac
|
97 |
print 'Included ' . $class_name . ' from ' . $path . '/' . $f . ' -> will now run job.' . "\n"; |
b1a6a5
|
98 |
|
MC |
99 |
$cronjob->run(); |
|
100 |
|
|
101 |
print 'run job (' . $class_name . ') done.' . "\n"; |
|
102 |
|
|
103 |
unset($cronjob); |
|
104 |
} |
5de2af
|
105 |
} |
M |
106 |
unset($files); |
|
107 |
|
bc0420
|
108 |
// Remove lock |
MB |
109 |
@unlink($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'); |
|
110 |
$app->log('Remove Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', LOGLEVEL_DEBUG); |
|
111 |
|
5de2af
|
112 |
die("finished.\n"); |
M |
113 |
|
|
114 |
?> |