mb-admin/scripts/check_litespeed.php

79 lines
2.6 KiB
PHP

<?php
// LiteSpeed Web Server Status Check for Virtuozzo LLSMP
// Focused on checking if LiteSpeed is running or not
// Function to execute system commands safely
function run_command($command) {
$output = [];
$return_var = 0;
exec($command . ' 2>&1', $output, $return_var);
return ['output' => $output, 'return_var' => $return_var];
}
// Function to check if LiteSpeed is running
function check_lsws_status() {
$result = run_command('systemctl is-active lsws');
if ($result['return_var'] !== 0) {
// Try alternative service names
$alt_services = ['lshttpd', 'litespeed'];
foreach ($alt_services as $service) {
$alt_result = run_command("systemctl is-active $service");
if ($alt_result['return_var'] === 0) {
return [
'running' => true,
'status' => $alt_result['output'][0] ?? 'active',
'service_name' => $service
];
}
}
}
return [
'running' => $result['return_var'] === 0,
'status' => $result['output'][0] ?? 'unknown',
'service_name' => 'lsws'
];
}
// Function to get LiteSpeed version (quick check)
function get_lsws_version() {
$result = run_command('/var/www/bin/lshttpd -v');
if ($result['return_var'] === 0 && !empty($result['output'])) {
foreach ($result['output'] as $line) {
if (preg_match('/LiteSpeed.*?(\d+\.\d+(?:\.\d+)?)/i', $line, $matches)) {
return $matches[1];
}
}
}
return 'unknown';
}
// Function to check LiteSpeed processes
function get_lsws_processes() {
$result = run_command('ps aux | grep -E "(lshttpd|litespeed)" | grep -v grep');
return count($result['output']);
}
// Main execution
try {
$lsws_status = check_lsws_status();
$lsws_version = get_lsws_version();
$process_count = get_lsws_processes();
// Simple focused output for litespeed_status action
echo json_encode([
'status' => $lsws_status['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"
], JSON_PRETTY_PRINT);
} catch (Exception $e) {
echo json_encode([
'status' => 'error',
'message' => 'Failed to check LiteSpeed status: ' . $e->getMessage()
], JSON_PRETTY_PRINT);
}