From df460c8b965b8beb83a7c27ca57608bd31f929b7 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 28 Feb 2026 16:11:19 +0800 Subject: [PATCH] feat: litespeed_status now reports cache enabled/disabled state alongside server status --- scripts/check_litespeed.php | 65 +++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/scripts/check_litespeed.php b/scripts/check_litespeed.php index e62b2b4..f034f87 100644 --- a/scripts/check_litespeed.php +++ b/scripts/check_litespeed.php @@ -54,26 +54,71 @@ 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" + 'version' => $lsws_version, + 'process_count' => $process_count, + '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) { echo json_encode([ - 'status' => 'error', + 'status' => 'error', 'message' => 'Failed to check LiteSpeed status: ' . $e->getMessage() ], JSON_PRETTY_PRINT); -} \ No newline at end of file +} \ No newline at end of file