FIX: Three critical bugs causing OPcache failures and script errors
1. **Unquoted array access in command substitution** (lines 2228-2229)
- Fixed: ${recommended_max_children[]} now properly quoted
- Impact: Values with spaces/special chars no longer break command substitution
2. **Unsafe grep in pipes with set -o pipefail** (lines 3221-3224)
- Added: || true to handle grep returning 1 when no matches
- Impact: Script no longer exits when no CRITICAL/HIGH/MEDIUM/LOW issues found
- This was causing silent failures in issue reporting
3. **Per-user OPcache check in per-domain loop** (lines 2483, 2804)
- Added: is_opcache_disabled_in_domain() function for per-domain checking
- Fixed: Now checks actual ini files per domain instead of per user
- Impact: Each domain's OPcache status properly detected
- Previously: All domains marked same (wrong) if user had it anywhere
These were causing:
- OPcache not being enabled when needed
- Script exits on certain domain configurations
- Incorrect OPcache detection across domains
All three are now fixed with proper per-domain checking.
This commit is contained in:
@@ -1256,6 +1256,33 @@ calculate_optimal_opcache_memory() {
|
||||
echo "${memory}M"
|
||||
}
|
||||
|
||||
# Check if OPcache is disabled in domain's ini files (per-domain check)
|
||||
is_opcache_disabled_in_domain() {
|
||||
local username="$1"
|
||||
local domain="$2"
|
||||
|
||||
local ini_files
|
||||
ini_files=$(find_php_ini_files "$username" "$domain")
|
||||
|
||||
while IFS= read -r ini_file; do
|
||||
[ -z "$ini_file" ] && continue
|
||||
[ ! -f "$ini_file" ] && continue
|
||||
|
||||
# Check if opcache.enable = 0 (explicitly disabled)
|
||||
if grep -q "^opcache.enable.*=.*0" "$ini_file" 2>/dev/null; then
|
||||
return 0 # OPcache IS disabled, needs enabling
|
||||
fi
|
||||
# Check if opcache.enable is not set at all
|
||||
if ! grep -q "^opcache.enable" "$ini_file" 2>/dev/null; then
|
||||
# Not explicitly set - may need enabling
|
||||
# We'll return 0 to try enabling it
|
||||
return 0
|
||||
fi
|
||||
done <<< "$ini_files"
|
||||
|
||||
return 1 # OPcache appears to be enabled
|
||||
}
|
||||
|
||||
# Enable OPcache in php.ini
|
||||
enable_opcache() {
|
||||
local ini_file="$1"
|
||||
@@ -2225,8 +2252,8 @@ optimize_level_3_advanced() {
|
||||
intel_result=$(calculate_optimal_php_settings_intelligent "$username" "$total_ram_mb" "$server_capacity" "$traffic_pct" 2>/dev/null || echo "20|dynamic|1|5|ERROR|Failed")
|
||||
|
||||
recommended_max_children["$domain"]=$(echo "$intel_result" | cut -d'|' -f1)
|
||||
recommended_memory_limit["$domain"]=$(calculate_optimal_memory_limit "$username" "$domain" "$recommended_max_children[$domain]" 2>/dev/null || echo "128M")
|
||||
recommended_max_requests["$domain"]=$(calculate_optimal_max_requests "$recommended_max_children[$domain]" 2>/dev/null || echo "0")
|
||||
recommended_memory_limit["$domain"]=$(calculate_optimal_memory_limit "$username" "$domain" "${recommended_max_children[$domain]}" 2>/dev/null || echo "128M")
|
||||
recommended_max_requests["$domain"]=$(calculate_optimal_max_requests "${recommended_max_children[$domain]}" 2>/dev/null || echo "0")
|
||||
fi
|
||||
|
||||
local current_max
|
||||
@@ -2480,13 +2507,14 @@ optimize_level_4_opcache() {
|
||||
while IFS= read -r domain; do
|
||||
[ -z "$domain" ] && continue
|
||||
|
||||
if is_opcache_enabled "$username"; then
|
||||
opcache_enabled["$domain"]="1"
|
||||
already_enabled=$((already_enabled + 1))
|
||||
else
|
||||
# Check per-domain ini files, not just per-user
|
||||
if is_opcache_disabled_in_domain "$username" "$domain"; then
|
||||
opcache_needs_enable["$domain"]="1"
|
||||
needs_enable_count=$((needs_enable_count + 1))
|
||||
cecho " ${YELLOW}⚠${NC} $domain: OPcache is disabled"
|
||||
else
|
||||
opcache_enabled["$domain"]="1"
|
||||
already_enabled=$((already_enabled + 1))
|
||||
fi
|
||||
done <<< "$user_domains"
|
||||
done <<< "$users"
|
||||
@@ -2773,7 +2801,8 @@ optimize_level_5_everything() {
|
||||
changes_count=$((changes_count + 1))
|
||||
fi
|
||||
|
||||
if ! is_opcache_enabled "$username"; then
|
||||
# Check per-domain ini files, not just per-user (fixes: all domains marked same if user has OPcache anywhere)
|
||||
if is_opcache_disabled_in_domain "$username" "$domain"; then
|
||||
opcache_needs_enable["$domain"]="1"
|
||||
opcache_count=$((opcache_count + 1))
|
||||
fi
|
||||
@@ -3217,11 +3246,11 @@ check_config_issues() {
|
||||
local has_medium=false
|
||||
local has_low=false
|
||||
|
||||
# Check for each severity level
|
||||
echo "$issues" | grep -q "CRITICAL" && has_critical=true
|
||||
echo "$issues" | grep -q "HIGH" && has_high=true
|
||||
echo "$issues" | grep -q "MEDIUM" && has_medium=true
|
||||
echo "$issues" | grep -q "LOW" && has_low=true
|
||||
# Check for each severity level (add || true to handle no matches with set -o pipefail)
|
||||
echo "$issues" | grep -q "CRITICAL" && has_critical=true || true
|
||||
echo "$issues" | grep -q "HIGH" && has_high=true || true
|
||||
echo "$issues" | grep -q "MEDIUM" && has_medium=true || true
|
||||
echo "$issues" | grep -q "LOW" && has_low=true || true
|
||||
|
||||
# Display CRITICAL
|
||||
if [ "$has_critical" = true ]; then
|
||||
|
||||
Reference in New Issue
Block a user