commit | author | age
|
87a4a6
|
1 |
<?php |
T |
2 |
/* |
039b46
|
3 |
Copyright (c) 2007-2011, Till Brehm, projektfarm Gmbh |
eed6b3
|
4 |
All rights reserved. |
87a4a6
|
5 |
|
eed6b3
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
V |
7 |
are permitted provided that the following conditions are met: |
87a4a6
|
8 |
|
eed6b3
|
9 |
* Redistributions of source code must retain the above copyright notice, |
V |
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
87a4a6
|
17 |
|
eed6b3
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
V |
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
87a4a6
|
29 |
|
8e9a5f
|
30 |
define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"])); |
7fe908
|
31 |
require SCRIPT_PATH."/lib/config.inc.php"; |
MC |
32 |
require SCRIPT_PATH."/lib/app.inc.php"; |
87a4a6
|
33 |
|
T |
34 |
set_time_limit(0); |
eed6b3
|
35 |
ini_set('error_reporting', E_ALL & ~E_NOTICE); |
87a4a6
|
36 |
|
T |
37 |
// make sure server_id is always an int |
be76b0
|
38 |
$conf['server_id'] = intval($conf['server_id']); |
87a4a6
|
39 |
|
32b40d
|
40 |
/* |
eed6b3
|
41 |
* Try to Load the server configuration from the master-db |
V |
42 |
*/ |
1d8f7f
|
43 |
if ($app->dbmaster->connect_error == NULL) { |
eed6b3
|
44 |
$server_db_record = $app->dbmaster->queryOneRecord("SELECT * FROM server WHERE server_id = " . $conf['server_id']); |
7fe908
|
45 |
|
5be510
|
46 |
if(!is_array($server_db_record)) die('Unable to load the server configuration from database.'); |
7fe908
|
47 |
|
MC |
48 |
//* Get the number of the last processed datalog_id, if the id of the local server |
72695f
|
49 |
//* is > then the one of the remote system, then use the local ID as we might not have |
T |
50 |
//* reached the remote server during the last run then. |
|
51 |
$local_server_db_record = $app->db->queryOneRecord("SELECT * FROM server WHERE server_id = " . $conf['server_id']); |
7fe908
|
52 |
$conf['last_datalog_id'] = (int) max($server_db_record['updated'], $local_server_db_record['updated']); |
72695f
|
53 |
unset($local_server_db_record); |
7fe908
|
54 |
|
eed6b3
|
55 |
$conf['mirror_server_id'] = (int) $server_db_record['mirror_server_id']; |
039b46
|
56 |
|
db0a6f
|
57 |
// Load the ini_parser |
T |
58 |
$app->uses('ini_parser'); |
039b46
|
59 |
|
db0a6f
|
60 |
// Get server configuration |
2a4cc6
|
61 |
$conf['serverconfig'] = $app->ini_parser->parse_ini_string(stripslashes($server_db_record['config'])); |
039b46
|
62 |
|
db0a6f
|
63 |
// Set the loglevel |
2a4cc6
|
64 |
$conf['log_priority'] = intval($conf['serverconfig']['server']['loglevel']); |
7fe908
|
65 |
|
615a0a
|
66 |
// Set level from which admin should be notified by email |
T |
67 |
if(!isset($conf['serverconfig']['server']['admin_notify_events']) || $conf['serverconfig']['server']['admin_notify_events'] == '') $conf['serverconfig']['server']['admin_notify_events'] = 3; |
|
68 |
$conf['admin_notify_priority'] = intval($conf['serverconfig']['server']['admin_notify_events']); |
eed6b3
|
69 |
|
039b46
|
70 |
// we do not need this variable anymore |
9adcf5
|
71 |
unset($server_db_record); |
7fe908
|
72 |
|
615a0a
|
73 |
// retrieve admin email address for notifications |
7b47c0
|
74 |
//$sys_ini = $app->dbmaster->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = 1"); |
T |
75 |
$sys_ini = $app->db->queryOneRecord("SELECT * FROM sys_ini WHERE sysini_id = 1"); |
615a0a
|
76 |
$conf['sys_ini'] = $app->ini_parser->parse_ini_string(stripslashes($sys_ini['config'])); |
T |
77 |
$conf['admin_mail'] = $conf['sys_ini']['mail']['admin_mail']; |
|
78 |
unset($sys_ini); |
7fe908
|
79 |
|
039b46
|
80 |
/* |
V |
81 |
* Save the rescue-config, maybe we need it (because the database is down) |
|
82 |
*/ |
|
83 |
$tmp['serverconfig']['server']['loglevel'] = $conf['log_priority']; |
|
84 |
$tmp['serverconfig']['rescue'] = $conf['serverconfig']['rescue']; |
|
85 |
file_put_contents(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt", serialize($tmp)); |
|
86 |
unset($tmp); |
|
87 |
|
|
88 |
// protect the file |
|
89 |
chmod(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt", 0600); |
7fe908
|
90 |
|
eed6b3
|
91 |
} else { |
V |
92 |
/* |
|
93 |
* The master-db is not available. |
|
94 |
* Problem: because we need to start the rescue-module (to rescue the DB if this IS the |
|
95 |
* server, the master-db is running at) we have to initialize some config... |
|
96 |
*/ |
7fe908
|
97 |
|
039b46
|
98 |
/* |
V |
99 |
* If there is a temp-file with the data we could get from the database, then we use it |
|
100 |
*/ |
|
101 |
$tmp = array(); |
|
102 |
if (file_exists(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt")){ |
|
103 |
$tmp = unserialize(file_get_contents(dirname(__FILE__) . "/temp/rescue_module_serverconfig.ser.txt")); |
|
104 |
} |
7fe908
|
105 |
|
039b46
|
106 |
// maxint at 32 and 64 bit systems |
7fe908
|
107 |
$conf['last_datalog_id'] = intval('9223372036854775807'); |
039b46
|
108 |
|
V |
109 |
// no mirror |
7fe908
|
110 |
$conf['mirror_server_id'] = 0; |
039b46
|
111 |
|
7fe908
|
112 |
// Set the loglevel |
039b46
|
113 |
$conf['log_priority'] = (isset($tmp['serverconfig']['server']['loglevel']))? $tmp['serverconfig']['server']['loglevel'] : LOGLEVEL_ERROR; |
eed6b3
|
114 |
/* |
V |
115 |
* Set the configuration to rescue the database |
|
116 |
*/ |
039b46
|
117 |
if (isset($tmp['serverconfig']['rescue'])){ |
V |
118 |
$conf['serverconfig']['rescue'] = $tmp['serverconfig']['rescue']; |
|
119 |
} |
|
120 |
else{ |
|
121 |
$conf['serverconfig']['rescue']['try_rescue'] = 'n'; |
|
122 |
} |
|
123 |
// we do not need this variable anymore |
|
124 |
unset($tmp); |
db0a6f
|
125 |
} |
T |
126 |
|
3d4630
|
127 |
|
9b82d2
|
128 |
// Check whether another instance of this script is already running |
eed6b3
|
129 |
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) { |
V |
130 |
clearstatcache(); |
|
131 |
for ($i = 0; $i < 120; $i++) { // Wait max. 1200 sec, then retry |
|
132 |
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) { |
|
133 |
exec("ps aux | grep '/usr/local/ispconfig/server/[s]erver.php' | wc -l", $check); |
|
134 |
if (intval($check[0]) > 1) { // 1 because this is 2nd instance! |
|
135 |
$app->log('There is already an instance of server.php running. Exiting.', LOGLEVEL_DEBUG); |
|
136 |
exit; |
|
137 |
} |
|
138 |
$app->log('There is already a lockfile set. Waiting another 10 seconds...', LOGLEVEL_DEBUG); |
|
139 |
sleep(10); |
|
140 |
clearstatcache(); |
|
141 |
} |
|
142 |
} |
87a4a6
|
143 |
} |
T |
144 |
|
|
145 |
// Set Lockfile |
eed6b3
|
146 |
@touch($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'); |
V |
147 |
$app->log('Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', LOGLEVEL_DEBUG); |
3d4630
|
148 |
|
eed6b3
|
149 |
/** Do we need to start the core-modules */ |
7fe908
|
150 |
|
MC |
151 |
|
eed6b3
|
152 |
$needStartCore = true; |
87a4a6
|
153 |
|
eed6b3
|
154 |
/* |
V |
155 |
* Next we try to process the datalog |
|
156 |
*/ |
1d8f7f
|
157 |
if ($app->db->connect_error == NULL && $app->dbmaster->connect_error == NULL) { |
9eff6c
|
158 |
|
d2d3b9
|
159 |
// Check if there is anything to update |
eed6b3
|
160 |
if ($conf['mirror_server_id'] > 0) { |
V |
161 |
$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)"); |
9adcf5
|
162 |
} else { |
eed6b3
|
163 |
$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)"); |
9adcf5
|
164 |
} |
eed6b3
|
165 |
|
2a4cc6
|
166 |
$tmp_num_records = $tmp_rec['number']; |
d2d3b9
|
167 |
unset($tmp_rec); |
7fe908
|
168 |
|
5a43e7
|
169 |
//** Load required base-classes |
ff6a68
|
170 |
$app->uses('modules,plugins,file,services,system'); |
5a43e7
|
171 |
//** Load the modules that are in the mods-enabled folder |
T |
172 |
$app->modules->loadModules('all'); |
|
173 |
//** Load the plugins that are in the plugins-enabled folder |
|
174 |
$app->plugins->loadPlugins('all'); |
ab6e69
|
175 |
|
MC |
176 |
$app->plugins->raiseAction('server_plugins_loaded', ''); |
|
177 |
|
eed6b3
|
178 |
if ($tmp_num_records > 0) { |
d2d3b9
|
179 |
$app->log("Found $tmp_num_records changes, starting update process.", LOGLEVEL_DEBUG); |
5a43e7
|
180 |
//** Go through the sys_datalog table and call the processing functions |
T |
181 |
//** from the modules that are hooked on to the table actions |
d2d3b9
|
182 |
$app->modules->processDatalog(); |
T |
183 |
} |
5a43e7
|
184 |
//** Process actions from sys_remoteaction table |
T |
185 |
$app->modules->processActions(); |
|
186 |
//** Restart services that need to after configuration |
|
187 |
$app->services->processDelayedActions(); |
|
188 |
//** All modules are already loaded and processed, so there is NO NEED to load the core once again... |
|
189 |
$needStartCore = false; |
7fe908
|
190 |
|
32b40d
|
191 |
} else { |
1d8f7f
|
192 |
if ($app->db->connect->connect_error == NULL) { |
eed6b3
|
193 |
$app->log('Unable to connect to local server.' . $app->db->errorMessage, LOGLEVEL_WARN); |
0e381b
|
194 |
} else { |
eed6b3
|
195 |
$app->log('Unable to connect to master server.' . $app->dbmaster->errorMessage, LOGLEVEL_WARN); |
0e381b
|
196 |
} |
782b02
|
197 |
} |
3d4630
|
198 |
|
eed6b3
|
199 |
/* |
V |
200 |
* Under normal circumstances the system was loaded and all updates are done. |
|
201 |
* but if we do not have to update anything or if the database is not accessible, then we |
|
202 |
* have to start the core-system (if the database is accessible, we need the core because of the |
|
203 |
* monitoring. If the databse is NOT accessible, we need the core because of rescue the db... |
|
204 |
*/ |
|
205 |
if ($needStartCore) { |
|
206 |
// Write the log |
|
207 |
$app->log('No Updated records found, starting only the core.', LOGLEVEL_DEBUG); |
|
208 |
// Load required base-classes |
|
209 |
$app->uses('modules,plugins,file,services'); |
|
210 |
// Load the modules that are im the mods-core folder |
|
211 |
$app->modules->loadModules('core'); |
cc6568
|
212 |
// Load the plugins that are in the f folder |
H |
213 |
//$app->plugins->loadPlugins('core'); |
eed6b3
|
214 |
} |
V |
215 |
|
|
216 |
|
87a4a6
|
217 |
// Remove lock |
eed6b3
|
218 |
@unlink($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'); |
V |
219 |
$app->log('Remove Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', LOGLEVEL_DEBUG); |
3d4630
|
220 |
|
32b40d
|
221 |
|
ba747c
|
222 |
die("finished.\n"); |
c30aaf
|
223 |
?> |