Fix OPcache toggle failure - enhance config file discovery for LiteSpeed paths
parent
0f819513e2
commit
d126152db6
17
mbadmin.jps
17
mbadmin.jps
|
|
@ -653,7 +653,22 @@ actions:
|
||||||
- cmd[cp]:
|
- cmd[cp]:
|
||||||
user: root
|
user: root
|
||||||
commands:
|
commands:
|
||||||
- php /home/litespeed/mbmanager/scripts/toggle_opcache.php disable
|
- |
|
||||||
|
set -euo pipefail
|
||||||
|
TMP_OUTPUT="$(mktemp)"
|
||||||
|
cleanup() {
|
||||||
|
rm -f "${TMP_OUTPUT}"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
php /home/litespeed/mbmanager/scripts/toggle_opcache.php disable > "${TMP_OUTPUT}"
|
||||||
|
|
||||||
|
if grep -Eq '"status"[[:space:]]*:[[:space:]]*"error"' "${TMP_OUTPUT}"; then
|
||||||
|
cat "${TMP_OUTPUT}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat "${TMP_OUTPUT}"
|
||||||
- restartNodes:
|
- restartNodes:
|
||||||
- nodeGroup: "cp"
|
- nodeGroup: "cp"
|
||||||
reboot: true
|
reboot: true
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ function find_php_config_files() {
|
||||||
'/etc/php/8.2/cli/conf.d/',
|
'/etc/php/8.2/cli/conf.d/',
|
||||||
'/etc/php/8.1/cli/conf.d/',
|
'/etc/php/8.1/cli/conf.d/',
|
||||||
'/etc/php/8.0/cli/conf.d/',
|
'/etc/php/8.0/cli/conf.d/',
|
||||||
|
'/usr/local/lsws/lsphp/etc/php.d/',
|
||||||
'/usr/local/lsws/lsphp84/etc/php.d/',
|
'/usr/local/lsws/lsphp84/etc/php.d/',
|
||||||
'/usr/local/lsws/lsphp83/etc/php.d/',
|
'/usr/local/lsws/lsphp83/etc/php.d/',
|
||||||
'/usr/local/lsws/lsphp82/etc/php.d/',
|
'/usr/local/lsws/lsphp82/etc/php.d/',
|
||||||
|
|
@ -42,7 +43,41 @@ function find_php_config_files() {
|
||||||
'/usr/local/lsws/lsphp80/etc/php.d/'
|
'/usr/local/lsws/lsphp80/etc/php.d/'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$possible_files = [
|
||||||
|
'/usr/local/lsws/lsphp/etc/php.d/10-opcache.ini',
|
||||||
|
'/etc/php.d/10-opcache.ini'
|
||||||
|
];
|
||||||
|
|
||||||
$config_files = [];
|
$config_files = [];
|
||||||
|
|
||||||
|
foreach ($possible_files as $file) {
|
||||||
|
if (is_file($file)) {
|
||||||
|
$config_files[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$loaded_ini = php_ini_loaded_file();
|
||||||
|
if ($loaded_ini !== false && is_file($loaded_ini)) {
|
||||||
|
$content = file_get_contents($loaded_ini);
|
||||||
|
if ($content !== false && preg_match('/^\s*;?\s*opcache\.enable\s*=\s*/mi', $content)) {
|
||||||
|
$config_files[] = $loaded_ini;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$scanned_ini = php_ini_scanned_files();
|
||||||
|
if ($scanned_ini !== false && trim($scanned_ini) !== '') {
|
||||||
|
foreach (explode(',', $scanned_ini) as $ini_file) {
|
||||||
|
$ini_file = trim($ini_file);
|
||||||
|
if ($ini_file === '' || !is_file($ini_file)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stripos(basename($ini_file), 'opcache') !== false) {
|
||||||
|
$config_files[] = $ini_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($possible_paths as $path) {
|
foreach ($possible_paths as $path) {
|
||||||
if (is_dir($path)) {
|
if (is_dir($path)) {
|
||||||
$files = glob($path . '*opcache*');
|
$files = glob($path . '*opcache*');
|
||||||
|
|
@ -52,7 +87,7 @@ function find_php_config_files() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $config_files;
|
return array_values(array_unique($config_files));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to modify OPcache configuration
|
// Function to modify OPcache configuration
|
||||||
|
|
@ -65,26 +100,35 @@ function modify_opcache_config($enable) {
|
||||||
|
|
||||||
$success = false;
|
$success = false;
|
||||||
foreach ($config_files as $file) {
|
foreach ($config_files as $file) {
|
||||||
if (is_writable($file)) {
|
if (!is_file($file)) {
|
||||||
$content = file_get_contents($file);
|
continue;
|
||||||
if ($content !== false) {
|
}
|
||||||
// Replace opcache.enable setting
|
|
||||||
if ($enable) {
|
|
||||||
$content = preg_replace('/^opcache\.enable\s*=\s*.*$/m', 'opcache.enable=1', $content);
|
|
||||||
$content = preg_replace('/^;opcache\.enable\s*=\s*.*$/m', 'opcache.enable=1', $content);
|
|
||||||
} else {
|
|
||||||
$content = preg_replace('/^opcache\.enable\s*=\s*.*$/m', 'opcache.enable=0', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no opcache.enable line exists, add it
|
$content = file_get_contents($file);
|
||||||
if (!preg_match('/^opcache\.enable\s*=/m', $content)) {
|
if ($content === false) {
|
||||||
$content .= "\nopcache.enable=" . ($enable ? '1' : '0') . "\n";
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_put_contents($file, $content) !== false) {
|
$replacement_count = 0;
|
||||||
$success = true;
|
$updated_content = preg_replace(
|
||||||
}
|
'/^\s*;?\s*opcache\.enable\s*=\s*.*$/mi',
|
||||||
}
|
'opcache.enable=' . ($enable ? '1' : '0'),
|
||||||
|
$content,
|
||||||
|
-1,
|
||||||
|
$replacement_count
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($updated_content === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no opcache.enable line exists, add it once.
|
||||||
|
if ($replacement_count === 0) {
|
||||||
|
$updated_content = rtrim($updated_content) . "\nopcache.enable=" . ($enable ? '1' : '0') . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_put_contents($file, $updated_content) !== false) {
|
||||||
|
$success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue