-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth.php
More file actions
56 lines (49 loc) · 2.29 KB
/
Copy pathhealth.php
File metadata and controls
56 lines (49 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
$root = __DIR__;
$response = [
'service' => 'DialecticServer',
'status' => 'unhealthy',
'version' => trim((string)@file_get_contents($root . DIRECTORY_SEPARATOR . '.version_number.txt')),
'build' => trim((string)@file_get_contents($root . DIRECTORY_SEPARATOR . '.version.txt')),
'database' => false,
'database_encoding' => '',
'database_encoding_supported' => false,
'schema' => false,
'background_processor' => false,
'background_port' => 12347,
'timestamp' => gmdate('c'),
];
try {
require_once $root . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'runtime_bootstrap.php';
require_once $root . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'dialectic_runtime.php';
require_once $root . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'background_processor.php';
dialecticRuntimeBootstrap($root, [
'run_db_updates' => false,
'load_general_settings' => false,
'load_stt_connector' => false,
'load_tts_connector' => false,
'load_player_name' => false,
'load_narrator' => false,
]);
$db = $GLOBALS['db'] ?? null;
$response['database'] = is_object($db) && (bool)$db->query('SELECT 1');
$response['database_encoding'] = $response['database'] ? dialecticRuntimeDatabaseEncoding() : '';
$response['database_encoding_supported'] = $response['database'] && dialecticRuntimeDatabaseEncodingIsSupported();
$response['schema'] = $response['database']
&& $response['database_encoding_supported']
&& !dialecticRuntimeNeedsDbUpdates();
$response['background_port'] = dialecticBackgroundProcessorPort();
$response['background_processor'] = dialecticBackgroundProcessorIsRunning(0.2);
$response['status'] = $response['schema'] ? 'ok' : 'degraded';
if ($response['database'] && !$response['database_encoding_supported']) {
$response['error'] = dialecticRuntimeDatabaseEncodingError();
}
} catch (Throwable $e) {
$response['error'] = $e->getMessage();
}
$healthy = $response['database'] && $response['schema'];
http_response_code($healthy ? 200 : 503);
echo json_encode($response, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n";