26 $valid_request = FALSE;
28 if (isset($_GET[
'checkdb']) || isset($_GET[
'checkreplication'])) {
29 $valid_request = TRUE;
33 if (isset($_GET[
'interrogate']) && $_GET[
'interrogate'] == 1) {
34 $valid_request = TRUE;
37 $LOCK_FILE = dirname(__FILE__) .
'/.test_message.lock';
39 if (!$valid_request) {
40 header(
'HTTP/1.0 200 OK');
41 echo
'the return code was 200';
45 if (is_file($LOCK_FILE)) {
46 # if the file was last modified < 55 secs ago, then show a 500 error.
47 # we want to limit it to 1 request every minute
48 # (55 secs used so we have a little leeway in case a request comes in slightly early)
49 $one_min_ago = time() - 55;
50 if (filemtime($LOCK_FILE) > $one_min_ago) {
51 header(
'HTTP/1.0 500 Internal Server Error');
61 if (!empty($_GET[
'checkdb']) || !empty($_GET[
'checkreplication'])) {
63 define(
'SQ_SYSTEM_ROOT',
'/app/matrix/');
64 define(
'SQ_LOG_PATH', SQ_SYSTEM_ROOT.
'/data/private/logs');
67 require_once SQ_SYSTEM_ROOT.
'/core/include/init.inc';
68 require SQ_SYSTEM_ROOT .
'/data/private/conf/db.inc';
70 if (isset($_GET[
'checkdb']) && $_GET[
'checkdb'] == 1) {
76 }
catch (Exception $e) {
85 }
catch (Exception $e) {
92 if (isset($_GET[
'checkreplication']) && $_GET[
'checkreplication'] == 1) {
94 $file_system_okay = TRUE;
100 $fp = fopen(
'/var/log/rsync.log',
'r');
107 if (time() > $info[
'mtime'] + (3 * 60)) {
108 $file_system_okay = FALSE;
111 fseek($fp, 0, SEEK_END);
116 fseek($fp, ftell($fp) - 2);
119 fseek($fp, ftell($fp) + 2);
120 $last_line = fgets($fp);
122 list($date, $time, $pid, $msg) = preg_split(
'/\s+/', $last_line, 4);
124 $error_msg =
'rsync error';
125 if (substr(trim($msg), 0, strlen($error_msg)) == $error_msg) {
126 $file_system_ok = FALSE;
130 $file_system_okay = FALSE;
136 $dsn_info = $db_conf[
'db'];
138 $dsn_info[
'username'] =
'repadm';
139 $dsn_info[
'password'] =
'repadm';
145 }
catch (Exception $e) {
156 }
catch (Exception $e) {
160 if (strtoupper($status) !==
'NORMAL') {
165 $sql =
'SELECT count(*) FROM deferror';
170 }
catch (Exception $e) {
179 $sql =
'SELECT count(*) FROM deftrandest';
185 }
catch (Exception $e) {
190 if ($trans < 0 || $trans > 200) {
195 if ($file_system_okay) {
197 $return_code =
'502';
201 $return_code =
'501';
203 $return_code =
'503';
208 if ($return_code ==
'200') {
209 header(
'HTTP/1.0 200 OK');
211 header(
'HTTP/1.0 '.$return_code.
' Internal Server Error');
213 echo
'the return code was '.$return_code;
233 define(
'SQ_SYSTEM_ROOT', realpath(dirname(__FILE__) .
'/../..'));
234 $return_code =
'200';
236 require_once SQ_SYSTEM_ROOT.
'/core/include/init.inc';
238 require SQ_SYSTEM_ROOT .
'/data/private/conf/db.inc';
241 'db' =>
'SELECT count(msgid) FROM sq_internal_msg',
242 'db2' =>
'UPDATE sq_ast SET updated = NOW() WHERE type_code = \'root_user\'',
243 'db3' =>
'UPDATE sq_ast SET updated = NOW() WHERE type_code = \'root_user\'',
244 'dbcache' =>
'SELECT count(assetid) FROM sq_cache',
245 'dbsearch' =>
'SELECT count(assetid) FROM sq_sch_idx'
248 $db_type = $db_conf[
'db'][
'type'];
253 $all_db_queries = array();
260 if ($db_type ==
'pgsql') {
261 $all_db_queries[] =
"SELECT count(*) as count from pg_stat_activity where current_query = '<IDLE>'";
267 if ($db_type ==
'oci8' || $db_type ==
'oci') {
268 $dsn_list[
'db2'] = str_replace(
'NOW()',
'SYSDATE', $dsn_list[
'db2']);
269 $dsn_list[
'db3'] = str_replace(
'NOW()',
'SYSDATE', $dsn_list[
'db3']);
273 foreach ($dsn_list as $dsn_name => $query) {
274 $start_time = time();
275 $output .= $dsn_name.
':';
286 if ($dsn_name ==
'dbcache') {
289 if ($dsn_name ==
'dbsearch') {
293 if (!isset($db_conf[$dsn_name])) {
294 $dsn_name = $alt_name;
297 if ($db_conf[$dsn_name] === null) {
298 $dsn_name = $alt_name;
304 $dsn = $db_conf[$dsn_name][
'DSN'];
306 if ($dsn !== $last_dsn) {
307 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection($dsn_name);
315 if (strtolower(substr($query, 0, 6)) ===
'select') {
320 }
catch (Exception $e) {
322 $return_code =
'500';
325 if ($res === NULL && ($dsn_name ==
'db2' || $dsn_name ==
'db3')) {
329 $output .= $res.
':'.ceil(time() - $start_time);
334 foreach ($all_db_queries as $qry) {
338 }
catch (Exception $e) {
339 $return_code =
'500';
342 $output .=
':' . $res;
350 if ($db_type ==
'pgsql') {
352 $slon_schema_query =
'SELECT REGEXP_REPLACE(trigger_name, \'(_logtrigger_|_denyaccess_)[0-9]+\', \'\') FROM information_schema.triggers WHERE (trigger_name LIKE \'%_logtrigger_%\' OR trigger_name LIKE \'%_denyaccess_%\') limit 1';
355 $slon_schema_lag_query =
'SELECT cast(extract(epoch from st_lag_time) as int8) FROM {SLON_SCHEMA}.sl_status WHERE st_origin = (SELECT last_value FROM {SLON_SCHEMA}.sl_local_node_id)';
361 $db_conf[
'dbslon'] = $db_conf[
'db2'];
365 $start_time = time();
369 }
catch (Exception $e) {
371 $return_code =
'500';
374 if (!empty($slon_schema)) {
375 $output .= $slon_schema.
':';
379 }
catch (Exception $e) {
381 $return_code =
'500';
386 $output .= $lag.
':'.ceil(time() - $start_time) .
"\n";
389 if ($return_code ==
'200') {
390 header(
'HTTP/1.0 200 OK');
392 header(
'HTTP/1.0 '.$return_code.
' Internal Server Error');