Enhance update script to allow user input for n8n worker count

- Added functionality to prompt the user for a new n8n worker count during the update process, including validation for positive integers.
- Improved error handling and logging for cases where the N8N_WORKER_COUNT line is missing in the .env file, ensuring better user guidance and script robustness.
This commit is contained in:
Yury Kossakovsky
2025-05-12 12:14:18 -06:00
parent 257656d53e
commit 8716bd7fb4

View File

@@ -63,8 +63,42 @@ if [ -f "$ENV_FILE" ]; then
sed -i 's/^RUN_N8N_IMPORT=.*/RUN_N8N_IMPORT=false/' "$ENV_FILE" || log_error "Failed to set RUN_N8N_IMPORT in $ENV_FILE. Check permissions."
;;
esac
# Ask user about n8n worker count
if grep -q "^N8N_WORKER_COUNT=" "$ENV_FILE"; then
CURRENT_WORKER_COUNT=$(grep "^N8N_WORKER_COUNT=" "$ENV_FILE" | cut -d'=' -f2 | tr -d '"')
log_info "Current n8n worker count: $CURRENT_WORKER_COUNT"
read -p "Enter new n8n worker count (leave empty to keep current: $CURRENT_WORKER_COUNT): " new_worker_count_raw
if [[ -n "$new_worker_count_raw" ]]; then
# Validate input: must be a positive integer
if [[ "$new_worker_count_raw" =~ ^[1-9][0-9]*$ ]]; then
NEW_WORKER_COUNT="$new_worker_count_raw"
log_info "Updating n8n worker count to $NEW_WORKER_COUNT in $ENV_FILE..."
# Use a temporary file for sed portability (-i needs backup suffix on macOS without -e)
sed "s/^N8N_WORKER_COUNT=.*/N8N_WORKER_COUNT=\\"$NEW_WORKER_COUNT\\"/" "$ENV_FILE" > "${ENV_FILE}.tmp" && mv "${ENV_FILE}.tmp" "$ENV_FILE" || {
log_error "Failed to update N8N_WORKER_COUNT in $ENV_FILE. Check permissions."
rm -f "${ENV_FILE}.tmp" # Clean up temp file on failure
}
else
log_warning "Invalid input '$new_worker_count_raw'. Worker count must be a positive integer. Keeping current value ($CURRENT_WORKER_COUNT)."
fi
else
log_info "Keeping current n8n worker count ($CURRENT_WORKER_COUNT)."
fi
else
# This case might occur if .env exists but N8N_WORKER_COUNT was manually removed.
# 03_generate_secrets.sh should ensure it exists on initial setup.
log_warning "N8N_WORKER_COUNT line not found in $ENV_FILE. Cannot update worker count during this update."
# Optionally, prompt user to add it if needed:
# read -p "N8N_WORKER_COUNT line not found. Add it now? (Enter number, or leave empty to skip): " add_worker_count
# if [[ "$add_worker_count" =~ ^[1-9][0-9]*$ ]]; then
# echo "N8N_WORKER_COUNT=\\"$add_worker_count\\"" >> "$ENV_FILE"
# log_info "Added N8N_WORKER_COUNT=$add_worker_count to $ENV_FILE."
# fi
fi
else
log_warning "$ENV_FILE not found. Cannot configure RUN_N8N_IMPORT."
log_warning "$ENV_FILE not found. Cannot configure RUN_N8N_IMPORT or N8N_WORKER_COUNT."
fi
# Start services using the 04_run_services.sh script