feat: litespeed_status now reports cache enabled/disabled state alongside server status
parent
20af8ad386
commit
df460c8b96
|
|
@ -54,21 +54,66 @@ function get_lsws_processes() {
|
|||
return count($result['output']);
|
||||
}
|
||||
|
||||
// Find WP-CLI binary
|
||||
function find_wp_cli() {
|
||||
$candidates = ['/usr/local/bin/wp', '/usr/bin/wp', '/home/litespeed/bin/wp'];
|
||||
foreach ($candidates as $path) {
|
||||
if (file_exists($path) && is_executable($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
$result = run_command('command -v wp');
|
||||
if ($result['return_var'] === 0 && !empty($result['output'][0])) {
|
||||
return trim($result['output'][0]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get LiteSpeed Cache plugin state via WP-CLI
|
||||
function get_cache_state() {
|
||||
$wp = find_wp_cli();
|
||||
$wp_root = '/var/www/webroot/ROOT';
|
||||
|
||||
if (!$wp || !file_exists($wp_root . '/wp-config.php')) {
|
||||
return ['enabled' => null, 'note' => 'WordPress or WP-CLI not found'];
|
||||
}
|
||||
|
||||
$result = run_command("sudo -u litespeed " . escapeshellarg($wp) . " --path=" . escapeshellarg($wp_root) . " litespeed-option get cache 2>/dev/null");
|
||||
if ($result['return_var'] !== 0 || empty($result['output'][0])) {
|
||||
return ['enabled' => null, 'note' => 'LiteSpeed Cache plugin not active or unavailable'];
|
||||
}
|
||||
|
||||
$value = trim($result['output'][0]);
|
||||
return [
|
||||
'enabled' => $value === '1',
|
||||
'raw' => $value
|
||||
];
|
||||
}
|
||||
|
||||
// Main execution
|
||||
try {
|
||||
$lsws_status = check_lsws_status();
|
||||
$lsws_version = get_lsws_version();
|
||||
$process_count = get_lsws_processes();
|
||||
$cache_state = get_cache_state();
|
||||
|
||||
$cache_enabled = $cache_state['enabled'];
|
||||
$cache_label = $cache_enabled === null
|
||||
? 'unknown'
|
||||
: ($cache_enabled ? 'enabled' : 'disabled');
|
||||
|
||||
$server_running = $lsws_status['running'];
|
||||
|
||||
// Simple focused output for litespeed_status action
|
||||
echo json_encode([
|
||||
'status' => $lsws_status['running'] ? 'running' : 'stopped',
|
||||
'status' => $server_running ? 'running' : 'stopped',
|
||||
'service_status' => $lsws_status['status'],
|
||||
'version' => $lsws_version,
|
||||
'process_count' => $process_count,
|
||||
'message' => $lsws_status['running']
|
||||
? "LiteSpeed Web Server v{$lsws_version} is running with {$process_count} processes"
|
||||
: "LiteSpeed Web Server is not running"
|
||||
'cache' => $cache_label,
|
||||
'cache_note' => $cache_state['note'] ?? null,
|
||||
'message' => $server_running
|
||||
? "LiteSpeed Web Server v{$lsws_version} is running | Cache: {$cache_label}"
|
||||
: "LiteSpeed Web Server is not running | Cache: {$cache_label}"
|
||||
], JSON_PRETTY_PRINT);
|
||||
|
||||
} catch (Exception $e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue