commit | author | age
|
87a4a6
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
00fad6
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
87a4a6
|
5 |
All rights reserved. |
T |
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 |
require("lib/config.inc.php"); |
|
32 |
require("lib/app.inc.php"); |
|
33 |
|
|
34 |
set_time_limit(0); |
ce6dcf
|
35 |
ini_set('error_reporting','E_ALL & ~E_NOTICE'); |
87a4a6
|
36 |
|
T |
37 |
// make sure server_id is always an int |
|
38 |
$conf["server_id"] = intval($conf["server_id"]); |
|
39 |
|
32b40d
|
40 |
/* |
87a4a6
|
41 |
// Get server record, if updates where available for this server |
32b40d
|
42 |
$server_db_record = $app->db->queryOneRecord("SELECT * FROM server WHERE update = 1 AND server_id = ".$conf["server_id"]); |
87a4a6
|
43 |
if($server_db_record == false) { |
T |
44 |
$app->log("Nothing to update for server_id ".$conf["server_id"]); |
|
45 |
die(); |
|
46 |
} else { |
|
47 |
// Set update status to 0, so we dont start the update process twice |
|
48 |
$app->db->query("UPDATE server SET update = 0 WHERE server_id = ".$conf["server_id"]); |
|
49 |
$app->log("Begin update."); |
|
50 |
} |
32b40d
|
51 |
*/ |
87a4a6
|
52 |
|
db0a6f
|
53 |
//* Load the server configuration |
T |
54 |
if($app->dbmaster->connect()) { |
|
55 |
// get the dalaog_id of the last performed record |
9adcf5
|
56 |
$server_db_record = $app->dbmaster->queryOneRecord("SELECT * FROM server WHERE server_id = ".$conf["server_id"]); |
db0a6f
|
57 |
$conf['last_datalog_id'] = (int)$server_db_record['updated']; |
9adcf5
|
58 |
$conf["mirror_server_id"] = (int)$server_db_record['mirror_server_id']; |
db0a6f
|
59 |
// Load the ini_parser |
T |
60 |
$app->uses('ini_parser'); |
|
61 |
// Get server configuration |
|
62 |
$conf["serverconfig"] = $app->ini_parser->parse_ini_string(stripslashes($server_db_record["config"])); |
|
63 |
// Set the loglevel |
|
64 |
$conf["log_priority"] = intval($conf["serverconfig"]["server"]["loglevel"]); |
9adcf5
|
65 |
|
T |
66 |
unset($server_db_record); |
db0a6f
|
67 |
} |
T |
68 |
|
3d4630
|
69 |
|
87a4a6
|
70 |
// Check if another process is running |
T |
71 |
if(is_file($conf["temppath"].$conf["fs_div"].".ispconfig_lock")){ |
|
72 |
clearstatcache(); |
11169c
|
73 |
for($i=0;$i<120;$i++){ // Wait max. 1200 sec, then proceed |
87a4a6
|
74 |
if(is_file($conf["temppath"].$conf["fs_div"].".ispconfig_lock")){ |
df0089
|
75 |
exec("ps aux | grep '/usr/local/ispconfig/server/server.php' | grep -v 'grep' | wc -l", $check); |
M |
76 |
if(intval($check[0]) > 1) { // 1 because this is 2nd instance! |
|
77 |
$app->log("There is already an instance of server.php running. Exiting.", LOGLEVEL_DEBUG); |
|
78 |
exit; |
|
79 |
} |
3d4630
|
80 |
$app->log("There is already a lockfile set. Waiting another 10 seconds...", LOGLEVEL_DEBUG); |
T |
81 |
sleep(10); |
87a4a6
|
82 |
clearstatcache(); |
T |
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
// Set Lockfile |
|
88 |
@touch($conf["temppath"].$conf["fs_div"].".ispconfig_lock"); |
32b40d
|
89 |
$app->log("Set Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock", LOGLEVEL_DEBUG); |
3d4630
|
90 |
|
87a4a6
|
91 |
|
0e381b
|
92 |
if($app->db->connect() && $app->dbmaster->connect()) { |
9eff6c
|
93 |
|
d2d3b9
|
94 |
// Check if there is anything to update |
9adcf5
|
95 |
if($conf["mirror_server_id"] > 0) { |
T |
96 |
$tmp_rec = $app->dbmaster->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = ".$conf["mirror_server_id"]." OR server_id = 0)"); |
|
97 |
} else { |
|
98 |
$tmp_rec = $app->dbmaster->queryOneRecord("SELECT count(server_id) as number from sys_datalog WHERE datalog_id > ".$conf['last_datalog_id']." AND (server_id = ".$conf["server_id"]." OR server_id = 0)"); |
|
99 |
} |
|
100 |
|
d2d3b9
|
101 |
$tmp_num_records = $tmp_rec["number"]; |
T |
102 |
unset($tmp_rec); |
|
103 |
|
|
104 |
if($tmp_num_records > 0) { |
|
105 |
/* |
|
106 |
There is something to do, triggert by the database -> do it! |
|
107 |
*/ |
|
108 |
// Write the Log |
|
109 |
$app->log("Found $tmp_num_records changes, starting update process.", LOGLEVEL_DEBUG); |
|
110 |
// Load required base-classes |
db0a6f
|
111 |
$app->uses('modules,plugins,file,services'); |
d2d3b9
|
112 |
// Load the modules that are im the mods-enabled folder |
T |
113 |
$app->modules->loadModules('all'); |
|
114 |
// Load the plugins that are in the plugins-enabled folder |
|
115 |
$app->plugins->loadPlugins('all'); |
|
116 |
// Go trough the sys_datalog table and call the processing functions |
|
117 |
// in the modules that are hooked on to the table actions |
|
118 |
$app->modules->processDatalog(); |
|
119 |
// Restart services that need to be restarted after configuration |
|
120 |
$app->services->processDelayedActions(); |
|
121 |
} else { |
|
122 |
/* |
|
123 |
There is no trigger inside the database -> load only the core, maybe they have to do something |
|
124 |
*/ |
|
125 |
// Write the log |
|
126 |
$app->log('No Updated records found, starting only the core.', LOGLEVEL_DEBUG); |
|
127 |
// Load required base-classes |
db0a6f
|
128 |
$app->uses('modules,plugins,file,services'); |
d2d3b9
|
129 |
// Load the modules that are im the mods-core folder |
T |
130 |
$app->modules->loadModules('core'); |
|
131 |
// Load the plugins that are in the plugins-core folder |
|
132 |
$app->plugins->loadPlugins('core'); |
|
133 |
} |
32b40d
|
134 |
} else { |
0e381b
|
135 |
if(!$app->db->connect()) { |
T |
136 |
$app->log("Unable to connect to local server.".$app->db->errorMessage,LOGLEVEL_WARN); |
|
137 |
} else { |
|
138 |
$app->log("Unable to connect to master server.".$app->dbmaster->errorMessage,LOGLEVEL_WARN); |
|
139 |
} |
782b02
|
140 |
} |
3d4630
|
141 |
|
87a4a6
|
142 |
// Remove lock |
T |
143 |
@unlink($conf["temppath"].$conf["fs_div"].".ispconfig_lock"); |
32b40d
|
144 |
$app->log("Remove Lock: ".$conf["temppath"].$conf["fs_div"].".ispconfig_lock",LOGLEVEL_DEBUG); |
3d4630
|
145 |
|
32b40d
|
146 |
|
ba747c
|
147 |
die("finished.\n"); |
c30aaf
|
148 |
?> |