135 lines
4.2 KiB
Bash
135 lines
4.2 KiB
Bash
#!/bin/bash
|
||
set -e
|
||
# ----------------------------------------------------------------------------------------------
|
||
# ------------------ Persistently set PHP-FPM pm.max_children on Unraid ------------------------
|
||
# ----------------------------------------------------------------------------------------------
|
||
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
|
||
# ----------------------------------------------------------------------------------------------
|
||
#
|
||
# User variables can be adjusted in Master.conf
|
||
#
|
||
# Scripts now just contain runtime logic
|
||
#
|
||
# This new setup allows for profiles and arguments to use the core script
|
||
# Use arguments in unRAID User Plugin for directory
|
||
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
|
||
# ----------------------------------------------------------------------------------------------
|
||
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
|
||
# ----------------------------------------------------------------------------------------------
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
||
source "$SCRIPT_DIR/../Master.conf"
|
||
source "$SCRIPT_DIR/../common.sh"
|
||
|
||
parse_args "$@"
|
||
|
||
# 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
|
||
|
||
# ROOT CHECK
|
||
if [[ "$EUID" -ne 0 ]]; then
|
||
error "🔴 Must be run as root"
|
||
fi
|
||
|
||
# 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
|
||
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
|
||
error "🔴 Failed to update PHP config"
|
||
fi
|
||
|
||
# Restart service
|
||
info "🟡 Restarting PHP-FPM"
|
||
|
||
if /etc/rc.d/rc.php-fpm restart; then
|
||
info "🟢 PHP-FPM restarted successfully"
|
||
else
|
||
error "🔴 PHP-FPM restart failed"
|
||
fi
|
||
|
||
# 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
|
||
}
|
||
|
||
# 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" |