diff --git a/scripts/import_workflows.sh b/scripts/import_workflows.sh old mode 100644 new mode 100755 index 37e6b75..ab1d8c1 --- a/scripts/import_workflows.sh +++ b/scripts/import_workflows.sh @@ -10,17 +10,28 @@ fi set -e +# Temp file for counter (pipes create subshells in POSIX sh) +COUNTER_FILE=$(mktemp) +trap 'rm -f "$COUNTER_FILE"' EXIT +echo "0" > "$COUNTER_FILE" + # Import credentials first echo 'Importing credentials...' CRED_FILES=$(find /backup/credentials -maxdepth 1 -type f -not -name '.gitkeep' 2>/dev/null || true) if [ -n "$CRED_FILES" ]; then CRED_COUNT=$(echo "$CRED_FILES" | wc -l | tr -d ' ') - CURRENT=0 + echo "0" > "$COUNTER_FILE" echo "$CRED_FILES" | while IFS= read -r file; do + CURRENT=$(cat "$COUNTER_FILE") CURRENT=$((CURRENT + 1)) + echo "$CURRENT" > "$COUNTER_FILE" filename=$(basename "$file") - echo "[$CURRENT/$CRED_COUNT] Importing credential: $filename" - n8n import:credentials --input="$file" 2>/dev/null || echo " Error importing: $filename" + printf "[%2d/%d] %s" "$CURRENT" "$CRED_COUNT" "$filename" + if n8n import:credentials --input="$file" >/dev/null 2>&1; then + echo " OK" + else + echo " FAILED" + fi done fi @@ -43,8 +54,7 @@ TOTAL=$(echo "$WORKFLOW_FILES" | wc -l | tr -d ' ') echo "Importing $TOTAL of $TOTAL_FOUND workflows" echo '' -# Use a counter file since pipes create subshells -COUNTER_FILE=$(mktemp) +# Reset counter for workflows echo "0" > "$COUNTER_FILE" echo "$WORKFLOW_FILES" | while IFS= read -r file; do @@ -62,7 +72,5 @@ echo "$WORKFLOW_FILES" | while IFS= read -r file; do fi done -rm -f "$COUNTER_FILE" - echo '' echo 'Import complete!' diff --git a/scripts/restart.sh b/scripts/restart.sh index 909a4bc..d67ae48 100755 --- a/scripts/restart.sh +++ b/scripts/restart.sh @@ -27,35 +27,42 @@ load_env PROJECT_NAME="localai" +# Time to wait for external services (Supabase, Dify) to initialize before starting main stack +EXTERNAL_SERVICE_INIT_DELAY=10 + # Build compose files array (sets global COMPOSE_FILES) build_compose_files_array log_info "Restarting services..." log_info "Using compose files: ${COMPOSE_FILES[*]}" -# Stop all services +# Stop all services using ALL compose files (including external stacks) +# This ensures clean shutdown of everything before restart docker compose -p "$PROJECT_NAME" "${COMPOSE_FILES[@]}" down # Start services in correct order (matching start_services.py behavior) -# Supabase must be started separately due to relative path resolution in its compose file +# NOTE: External stacks (Supabase, Dify) must be started SEPARATELY because their +# compose files use relative paths for volumes/configs. When combined with main +# docker-compose.yml via -f flags, the relative paths resolve incorrectly. +# Solution: Start external stacks first from their own directories, then start main stack. + if is_profile_active "supabase"; then SUPABASE_COMPOSE="$PROJECT_ROOT/supabase/docker/docker-compose.yml" if [ -f "$SUPABASE_COMPOSE" ]; then log_info "Starting Supabase services..." docker compose -p "$PROJECT_NAME" -f "$SUPABASE_COMPOSE" up -d log_info "Waiting for Supabase to initialize..." - sleep 10 + sleep "$EXTERNAL_SERVICE_INIT_DELAY" fi fi -# Start Dify separately (same relative path issue) if is_profile_active "dify"; then DIFY_COMPOSE="$PROJECT_ROOT/dify/docker/docker-compose.yaml" if [ -f "$DIFY_COMPOSE" ]; then log_info "Starting Dify services..." docker compose -p "$PROJECT_NAME" -f "$DIFY_COMPOSE" up -d log_info "Waiting for Dify to initialize..." - sleep 10 + sleep "$EXTERNAL_SERVICE_INIT_DELAY" fi fi