fix(6): ensure background processes run from correct directories

- Wrap backend uvicorn with proper working directory subshell
- Wrap frontend Next.js server with proper working directory subshell
- Use subshell syntax (cd && run) to ensure processes inherit correct context
- Fixes processes starting but immediately crashing
This commit is contained in:
2026-04-22 18:35:53 +03:00
parent 66464cb148
commit aef38e871f

View File

@@ -128,9 +128,9 @@ if [[ ! -f "../$DATA_DIR/inventory.db" ]]; then
python3 -c "from db_manager import init_db; init_db()" || true
fi
# Start uvicorn in background
# Start uvicorn in background (with proper working directory)
log_info " Starting uvicorn server..."
python3 -m uvicorn main:app --host 0.0.0.0 --port "$BACKEND_PORT" --log-level "${LOG_LEVEL,,}" >> "$BACKEND_LOG" 2>&1 &
(cd "$(pwd)" && python3 -m uvicorn main:app --host 0.0.0.0 --port "$BACKEND_PORT" --log-level "${LOG_LEVEL,,}" >> "$BACKEND_LOG" 2>&1) &
BACKEND_PID=$!
log_success " ✓ Backend started (PID: $BACKEND_PID, Port: $BACKEND_PORT)"
@@ -163,9 +163,10 @@ if [[ ! -d ".next" ]]; then
npm run build || log_error "Failed to build frontend"
fi
# Start Next.js in production mode
# Start Next.js in production mode (with proper working directory)
log_info " Starting Next.js server..."
PORT="$FRONTEND_PORT" node .next/standalone/server.js >> "$FRONTEND_LOG" 2>&1 &
FRONTEND_DIR="$(pwd)"
(cd "$FRONTEND_DIR" && PORT="$FRONTEND_PORT" node .next/standalone/server.js >> "$FRONTEND_LOG" 2>&1) &
FRONTEND_PID=$!
log_success " ✓ Frontend started (PID: $FRONTEND_PID, Port: $FRONTEND_PORT)"