#!/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"