Updated framework

This commit is contained in:
2026-03-27 16:50:20 +00:00
parent 24c7a481c8
commit 4faf5d2b96
11 changed files with 994 additions and 398 deletions
+98 -25
View File
@@ -18,45 +18,118 @@ set -e
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# Load central config
load_master_conf
# Parse CLI args (supports --dry-run)
parse_args "$@"
# Require root
if [ "$EUID" -ne 0 ]; then
echo -e "\033[0;31m❌ Please run as root.${RESET}\n"
exit 1
# STATUS MODE
if [[ "$SHOW_STATUS" == true ]]; then
echo
echo "=================================================="
echo " ️ PHP-FPM CONFIG STATUS"
echo "--------------------------------------------------"
echo " ⚙️ PHP_CONF: $PHP_CONF"
echo " 👥 Max Children: ${PHP_MAX_CHILDREN:-unset}"
echo " 🧪 Dry Run: $DRY_RUN"
echo "=================================================="
exit 0
fi
validate_int PHP_MAX_CHILDREN "$PHP_MAX_CHILDREN"
# ROOT CHECK
if [[ "$EUID" -ne 0 ]]; then
error "🔴 Must be run as root"
fi
# Functions
# VALIDATION
validate_int PHP_MAX_CHILDREN "$PHP_MAX_CHILDREN"
require_var PHP_CONF
# HEADER
echo
echo "============================================================"
echo " 🚀 PHP-FPM CONFIG UPDATE STARTING"
echo "------------------------------------------------------------"
echo " ⚙️ Target: $PHP_CONF"
echo " 👥 MaxChild: $PHP_MAX_CHILDREN"
echo " 🧪 Dry Run: $DRY_RUN"
echo "============================================================"
log "️ Starting PHP-FPM configuration update"
# FUNCTIONS
apply_php_max_children() {
local target="pm.max_children = $PHP_MAX_CHILDREN"
if [ "$DRY_RUN" = true ]; then
echo "[DRY-RUN] Would set PHP-FPM max_children to $PHP_MAX_CHILDREN in $PHP_CONF"
echo "[DRY-RUN] Would restart PHP-FPM service"
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would set pm.max_children = $PHP_MAX_CHILDREN"
warn "🧪 Would restart PHP-FPM service"
return
fi
info "🟡 Applying PHP-FPM configuration"
if [[ ! -f "$PHP_CONF" ]]; then
error "🔴 PHP config file not found: $PHP_CONF"
fi
# Apply config safely
if sed -i "s/^pm\.max_children.*/$target/" "$PHP_CONF"; then
info "🟢 Config updated successfully"
else
echo "Applying persistent PHP-FPM max_children = $PHP_MAX_CHILDREN"
sed -i "s/^pm\.max_children.*/$target/" "$PHP_CONF"
error "🔴 Failed to update PHP config"
fi
# Restart PHP-FPM
/etc/rc.d/rc.php-fpm restart
# Restart service
info "🟡 Restarting PHP-FPM"
local current
current=$(grep -E "^pm\.max_children" "$PHP_CONF")
logger "Userscript: php-fpm setting applied: $current"
if /etc/rc.d/rc.php-fpm restart; then
info "🟢 PHP-FPM restarted successfully"
else
error "🔴 PHP-FPM restart failed"
fi
echo "PHP-FPM max_children persistently set to: $current"
echo "PHP-FPM restarted successfully."
# Verify applied value
local current
current=$(grep -E "^pm\.max_children" "$PHP_CONF" || true)
if [[ -n "$current" ]]; then
info "🟢 Verified: $current"
logger "Userscript: PHP-FPM updated -> $current"
else
warn "🟡 Could not verify configuration value"
fi
}
# MAIN
echo "==== PHP-FPM Max Children Script Started: $(date) ===="
apply_php_max_children
# EXECUTION
START_TIME=$(date +%s)
apply_php_max_children
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# SUMMARY
echo
echo "============================================================"
if [[ "$DRY_RUN" == true ]]; then
echo " 🟡 PHP-FPM SUMMARY"
echo "------------------------------------------------------------"
echo " ⚙️ Target: $PHP_CONF"
echo " 👥 MaxChild: $PHP_MAX_CHILDREN"
echo " 📡 Status: 🟡 DRY RUN"
else
echo " 🟢 PHP-FPM SUMMARY"
echo "------------------------------------------------------------"
echo " ⚙️ Target: $PHP_CONF"
echo " 👥 MaxChild: $PHP_MAX_CHILDREN"
echo " ⏱ Duration: ${DURATION}s"
echo " 📡 Status: 🟢 SUCCESS"
fi
echo "============================================================"
info "️ PHP-FPM configuration update complete"