Compare commits
2 Commits
95429dc192
...
cdf4be35f6
| Author | SHA1 | Date | |
|---|---|---|---|
| cdf4be35f6 | |||
| 7c960c4870 |
@@ -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..."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user