ids.alfacom.it/deployment/check_frontend.sh
marco370 e5d038a2b4 Improve how the application starts to ensure environment variables are loaded correctly
Modify deployment/check_frontend.sh to use `env $(cat .env | grep -v '^#' | xargs) npm run dev` to inject environment variables into the npm process, resolving issues where `nohup` did not inherit exported variables. Update replit.md to reflect the corrected fix details.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 602cd9af-422f-4b1d-ab37-5fd3e0bd016f
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/dI1I79r
2025-11-21 15:58:17 +00:00

42 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# =========================================================
# CHECK FRONTEND - Verifica e riavvia frontend Node.js se necessario
# =========================================================
PROCESS_NAME="npm run dev"
PID_FILE="/var/log/ids/frontend.pid"
LOG_FILE="/var/log/ids/frontend.log"
WORK_DIR="/opt/ids"
mkdir -p /var/log/ids
# Check if frontend is running
if pgrep -f "vite" > /dev/null; then
# Frontend running, update PID
pgrep -f "vite" > "$PID_FILE"
exit 0
else
echo "[$(date)] Frontend Node NON attivo, riavvio..." >> "$LOG_FILE"
# Kill any orphaned Node processes
pkill -f "vite" 2>/dev/null
pkill -f "npm run dev" 2>/dev/null
# Wait a moment
sleep 2
# Start frontend with environment variables from .env
cd "$WORK_DIR"
if [ -f "$WORK_DIR/.env" ]; then
# Load .env and start npm with those variables
nohup env $(cat "$WORK_DIR/.env" | grep -v '^#' | xargs) npm run dev >> "$LOG_FILE" 2>&1 &
else
# Fallback: start without .env (will use system env vars)
nohup npm run dev >> "$LOG_FILE" 2>&1 &
fi
NEW_PID=$!
echo $NEW_PID > "$PID_FILE"
echo "[$(date)] Frontend riavviato con PID: $NEW_PID" >> "$LOG_FILE"
fi