Compare commits

..

2 Commits

Author SHA1 Message Date
cschantz cdf4be35f6 Add change tracking and history display to Option 5
- Initialize change tracking before applying optimizations
- Log each change made during optimization process
- Track before/after values for all modifications
- Display detailed change log after optimization completes
- Show recent change history from change tracker
- Provides auditability and visibility into what changed

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-17 23:00:03 -05:00
cschantz 7c960c4870 Add preview of changes before applying optimizations to Option 5
- Display all changes that will be made with per-domain breakdown
- Show memory impact per domain and total impact
- Calculate memory freed/allocated for each change
- Require final confirmation before actually applying changes
- Provides safety check to prevent accidental bad configurations

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-17 22:59:37 -05:00
+141 -1
View File
@@ -926,11 +926,118 @@ optimize_all_domains() {
;;
esac
# ========================================================================
# STEP 3: PREVIEW CHANGES BEFORE APPLYING
# ========================================================================
show_banner
cecho "${WHITE}${BOLD}PREVIEW: Changes that will be applied${NC}"
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
echo ""
local preview_count=0
local preview_total_impact=0
# Get all users for preview
local preview_users
preview_users=$(list_all_users)
while IFS= read -r username; do
[ -z "$username" ] && continue
local user_domains
user_domains=$(get_user_domains "$username")
while IFS= read -r domain; do
[ -z "$domain" ] && continue
# Check if this domain/user was selected
local should_preview=false
if [ "$SYS_CONTROL_PANEL" = "cpanel" ]; then
[ "${domains_to_apply[$domain]}" = "true" ] && should_preview=true
else
[ "${domains_to_apply[$username]}" = "true" ] && should_preview=true
fi
if [ "$should_preview" = "false" ]; then
continue
fi
preview_count=$((preview_count + 1))
# Get current pool config
local pool_config
pool_config=$(find_fpm_pool_config "$username" "$domain" 2>/dev/null)
if [ -z "$pool_config" ] || [ ! -f "$pool_config" ]; then
continue
fi
# Get current and recommended values
local current_max recommended_max
current_max=$(grep "^pm.max_children" "$pool_config" 2>/dev/null | awk -F'=' '{print $2}' | tr -d ' ')
if [ "$SYS_CONTROL_PANEL" = "cpanel" ]; then
recommended_max="${recommended_values[$domain]}"
else
recommended_max="${recommended_values[$username]}"
fi
if [ -z "$current_max" ] || [ -z "$recommended_max" ]; then
continue
fi
# Calculate memory impact (assume 20MB per process on average)
local memory_freed=$((( current_max - recommended_max ) * 20))
if [ "$current_max" -ne "$recommended_max" ]; then
cecho " ${CYAN}[$preview_count]${NC} $domain"
cecho " Current: pm.max_children = ${YELLOW}$current_max${NC}"
cecho " Change to: pm.max_children = ${GREEN}$recommended_max${NC}"
if [ "$memory_freed" -gt 0 ]; then
cecho " Memory freed: ${GREEN}+${memory_freed}MB${NC}"
preview_total_impact=$((preview_total_impact + memory_freed))
elif [ "$memory_freed" -lt 0 ]; then
cecho " Memory allocated: ${YELLOW}$((-memory_freed))MB${NC} (growth)"
fi
echo ""
fi
done <<< "$user_domains"
done <<< "$preview_users"
if [ "$preview_count" -eq 0 ]; then
cecho "${YELLOW}No changes to preview${NC}"
echo ""
read -p "Press Enter to continue..."
return
fi
echo ""
cecho "${CYAN}═══════════════════════════════════════════════════════════════════${NC}"
cecho "${WHITE}${BOLD}PREVIEW SUMMARY${NC}"
cecho " Total changes: ${WHITE}$preview_count${NC}"
if [ "$preview_total_impact" -gt 0 ]; then
cecho " Total memory that could be freed: ${GREEN}+${preview_total_impact}MB${NC}"
fi
echo ""
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
# Ask for final confirmation before applying
if ! confirm "Apply these changes?"; then
cecho "${YELLOW}Optimization cancelled${NC}"
read -p "Press Enter to continue..."
return
fi
show_banner
cecho "${WHITE}${BOLD}Applying optimizations...${NC}"
cecho "${CYAN}Selected: ${#domains_to_apply[@]} domain(s)/user(s)${NC}"
echo ""
# Initialize change tracking
init_change_tracking 2>/dev/null || true
# Get all users
local users
users=$(list_all_users)
@@ -946,6 +1053,7 @@ optimize_all_domains() {
local optimized_count=0
local skipped_count=0
declare -A optimization_summary
declare -a changes_made_list
# Process each user
while IFS= read -r username; do
@@ -1046,6 +1154,10 @@ optimize_all_domains() {
if [ "$changes_made" -gt 0 ]; then
cecho " ${GREEN}${NC} Optimized ($changes_made changes): $changes_list"
optimized_count=$((optimized_count + 1))
# Log the change
log_change "$domain|$username" "pm.max_children" "$current_max_children" "$recommended_max_children" "Server-wide optimization" 2>/dev/null || true
changes_made_list+=("$domain: $current_max_children$recommended_max_children (freed ~$((( current_max_children - recommended_max_children ) * 20))MB)")
else
if [ -n "$changes_list" ]; then
cecho " ${YELLOW}${NC} Detected: $changes_list (manual intervention needed)"
@@ -1095,7 +1207,35 @@ optimize_all_domains() {
fi
echo ""
cecho "${CYAN}═══════════════════════════════════════════════════════════════════${NC}"
# Display change history
if [ "${#changes_made_list[@]}" -gt 0 ]; then
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
cecho "${WHITE}${BOLD}DETAILED CHANGES${NC}"
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
echo ""
for change in "${changes_made_list[@]}"; do
cecho " ${GREEN}${NC} $change"
done
echo ""
# Get recent change history from tracker
local recent_changes
recent_changes=$(get_change_history 2>/dev/null || echo "")
if [ -n "$recent_changes" ]; then
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
cecho "${WHITE}${BOLD}CHANGE HISTORY${NC}"
cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}"
echo ""
cecho "$recent_changes" | head -20 # Show last 20 changes
echo ""
fi
fi
cecho "${CYAN}═════════════════════════════════════════════════════════════════════${NC}"
echo ""
read -p "Press Enter to continue..."
}