Files
Varaverk/unRAID Essentials/php_fpm_max_children.sh
T

62 lines
2.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/../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
fi
validate_int PHP_MAX_CHILDREN "$PHP_MAX_CHILDREN"
# 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"
else
echo "Applying persistent PHP-FPM max_children = $PHP_MAX_CHILDREN"
sed -i "s/^pm\.max_children.*/$target/" "$PHP_CONF"
# Restart PHP-FPM
/etc/rc.d/rc.php-fpm restart
local current
current=$(grep -E "^pm\.max_children" "$PHP_CONF")
logger "Userscript: php-fpm setting applied: $current"
echo "PHP-FPM max_children persistently set to: $current"
echo "PHP-FPM restarted successfully."
fi
}
# MAIN
echo "==== PHP-FPM Max Children Script Started: $(date) ===="
apply_php_max_children