-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_status.php
More file actions
84 lines (67 loc) · 2.78 KB
/
Copy pathserver_status.php
File metadata and controls
84 lines (67 loc) · 2.78 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
/**
* Server status and recovery console.
*
* The one page that must stay useful when MySQL refuses to boot: it never opens
* a database connection to render, diagnoses every configured server, and can
* start or stop the Windows services directly.
*/
require __DIR__ . '/lib/bootstrap.php';
use DbManager\Security;
use DbManager\ServerDiagnostics;
use DbManager\ServiceControl;
use DbManager\View;
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
try {
Security::assertValidRequest();
$serverKey = request_str('server_key');
$action = request_str('action');
$server = registry()->get($serverKey);
if (!$server->hasService()) {
throw new RuntimeException(__('service.no_service', [':server' => $server->displayName()]));
}
$result = match ($action) {
'start' => ServiceControl::start((string) $server->serviceName),
'stop' => ServiceControl::stop((string) $server->serviceName),
'restart' => ServiceControl::restart((string) $server->serviceName),
default => throw new RuntimeException(__('service.unknown_action', [':action' => $action])),
};
flash($result['ok'] ? 'success' : 'error', $result['message']);
} catch (Throwable $exception) {
flash('error', $exception->getMessage());
}
redirect(url('server_status.php', ['server' => request_str('server_key')]));
}
// Windows service state costs a PowerShell spawn (seconds). It is collected
// automatically when a server looks broken, and on demand via ?deep=1.
$deep = request_str('deep') === '1' ? true : null;
$reports = [];
foreach (registry()->all() as $key => $server) {
$reports[$key] = ServerDiagnostics::inspect($server, $deep);
}
$critical = count(array_filter(
$reports,
static fn (array $report): bool => $report['level'] === ServerDiagnostics::LEVEL_CRITICAL
));
$autoRefresh = request_str('auto') === '1';
$actions = '<a class="btn" href="' . e(url('server_status.php', ['auto' => $autoRefresh ? null : '1'])) . '">'
. icon('refresh') . '<span>' . e($autoRefresh ? __('status.auto_off') : __('status.auto_on')) . '</span></a>'
. '<a class="btn btn--primary" href="' . e(url('server_status.php')) . '">'
. icon('activity') . '<span>' . e(__('status.rescan')) . '</span></a>';
View::render(
'server_status',
[
'reports' => $reports,
'autoRefresh' => $autoRefresh,
'serviceControl' => ServiceControl::isEnabled(),
],
[
'title' => __('status.title'),
'subtitle' => $critical > 0
? __('status.subtitle_critical', [':count' => $critical])
: __('status.subtitle_ok'),
'active' => 'status',
'actions' => $actions,
]
);