all scripts are now current with common.sh v2.1
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
#!/bin/bash
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ----------------------------- PHP-FPM Max Children Script ------------------------------------
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# Persistently sets PHP-FPM pm.max_children on unRAID.
|
||||
# Config file path and max children value are set in Master.conf.
|
||||
# Supports --dry-run to preview what would be changed without making changes.
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$SCRIPT_DIR/../Master.conf"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
|
||||
parse_args "$@"
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_GEAR Setup ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━ $ICON_GEAR Setup ━━━"
|
||||
|
||||
# ROOT CHECK
|
||||
if [[ "$EUID" -ne 0 ]]; then
|
||||
error "Must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "Running as root"
|
||||
|
||||
# VALIDATION
|
||||
validate_int PHP_MAX_CHILDREN "$PHP_MAX_CHILDREN"
|
||||
require_var PHP_CONF
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_SUMMARY Status ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
if [[ "$SHOW_STATUS" == true ]]; then
|
||||
echo ""
|
||||
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
|
||||
echo "$ICON_GEAR Config File: $PHP_CONF"
|
||||
echo "$ICON_PHP Max Children: $PHP_MAX_CHILDREN"
|
||||
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# FUNCTIONS
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
|
||||
# Applies pm.max_children to the PHP-FPM config file and restarts the service.
|
||||
# Verifies the value was applied correctly after restart.
|
||||
# Skips all changes if dry run is active.
|
||||
apply_php_max_children() {
|
||||
local target="pm.max_children = $PHP_MAX_CHILDREN"
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
warn "DRY RUN — would set pm.max_children = $PHP_MAX_CHILDREN in $PHP_CONF"
|
||||
warn "DRY RUN — would restart PHP-FPM service"
|
||||
return
|
||||
fi
|
||||
|
||||
# Verify config file exists before attempting changes
|
||||
if [[ ! -f "$PHP_CONF" ]]; then
|
||||
error "PHP config file not found: $PHP_CONF"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
info "Applying pm.max_children = $PHP_MAX_CHILDREN..."
|
||||
|
||||
if sed -i "s/^pm\.max_children.*/$target/" "$PHP_CONF"; then
|
||||
success "Config updated"
|
||||
else
|
||||
error "Failed to update PHP config: $PHP_CONF"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
info "Restarting PHP-FPM..."
|
||||
|
||||
if /etc/rc.d/rc.php-fpm restart; then
|
||||
success "PHP-FPM restarted"
|
||||
else
|
||||
error "PHP-FPM restart failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify the value was applied correctly
|
||||
local current
|
||||
current=$(grep -E "^pm\.max_children" "$PHP_CONF" || true)
|
||||
|
||||
if [[ -n "$current" ]]; then
|
||||
success "Verified: $current"
|
||||
logger "Userscript: PHP-FPM updated → $current"
|
||||
else
|
||||
warn "Could not verify configuration value — check $PHP_CONF manually"
|
||||
fi
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_PHP PHP-FPM Config ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━ $ICON_PHP PHP-FPM Config ━━━"
|
||||
echo "$ICON_GEAR Config File: $PHP_CONF"
|
||||
echo "$ICON_PHP Max Children: $PHP_MAX_CHILDREN"
|
||||
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
||||
echo ""
|
||||
|
||||
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
|
||||
|
||||
START=$(date +%s)
|
||||
|
||||
apply_php_max_children
|
||||
|
||||
END=$(date +%s)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_SUMMARY Summary ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━━━ $ICON_SUMMARY PHP-FPM SUMMARY ━━━━━"
|
||||
echo "$ICON_GEAR Config File: $PHP_CONF"
|
||||
echo "$ICON_PHP Max Children: $PHP_MAX_CHILDREN"
|
||||
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
echo "$ICON_WARN Status: DRY RUN — no changes made"
|
||||
else
|
||||
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
|
||||
fi
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
Reference in New Issue
Block a user