Enhance server startup and log monitoring scripts

- Updated `rebuild.sh` to include error handling for directory changes and improved server startup checks, providing clearer feedback on server status.
- Enhanced `watch-activity.sh` to wait for the log file creation with a timeout and added user guidance for ensuring server activity logging.
- Improved user feedback in both scripts to facilitate easier debugging and monitoring of server and log file states.
This commit is contained in:
ilia 2026-01-04 22:00:15 -05:00
parent 79e6656b02
commit 1aff435ca1
3 changed files with 52 additions and 13 deletions

View File

@ -26,13 +26,21 @@ export default function LoginPage() {
if (result?.error) {
setError("Invalid email or password")
} else if (result?.ok) {
// Force a session refresh before redirect
// This ensures the session cookie is properly set and read
await fetch("/api/auth/session", { method: "GET" })
// Check if there's a callback URL in the query params
const params = new URLSearchParams(window.location.search)
const callbackUrl = params.get("callbackUrl") || "/photos"
console.log("Redirecting to:", callbackUrl)
// Use window.location.href to force a full page reload
// This ensures the session cookie is read before middleware checks authentication
window.location.href = callbackUrl
// Small delay to ensure cookie is set
setTimeout(() => {
// Use window.location.href to force a full page reload
// This ensures the session cookie is read before middleware checks authentication
window.location.href = callbackUrl
}, 100)
} else {
setError("Login failed. Please try again.")
}

View File

@ -8,7 +8,10 @@ set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
cd "$SCRIPT_DIR" || {
echo "Error: Could not change to script directory: $SCRIPT_DIR"
exit 1
}
MODE=${1:-prod}
@ -71,13 +74,23 @@ else
export NODE_ENV=production
unset AUTH_TRUST_HOST
npm run start > "$LOG_FILE" 2>&1 &
echo "Server PID: $!"
SERVER_PID=$!
echo "Server PID: $SERVER_PID"
echo "Log file: $LOG_FILE"
echo ""
sleep 3
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200\|307"; then
echo "✓ Server is running on http://localhost:3000"
else
echo "⚠ Server may still be starting. Check logs: tail -f $LOG_FILE"
fi
# Wait for server to start (check log file for "Ready" message or check HTTP)
echo "Waiting for server to start..."
for i in {1..30}; do
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 2>/dev/null | grep -q "200\|307\|404"; then
echo "✓ Server is running on http://localhost:3000"
break
fi
if [ $i -eq 30 ]; then
echo "⚠ Server may still be starting. Check logs: tail -f $LOG_FILE"
echo " Or check if process is running: ps -p $SERVER_PID"
else
sleep 1
fi
done
fi

View File

@ -23,10 +23,28 @@ if [ -n "$LOG_FILE" ]; then
# Watch log file
if [ ! -f "$LOG_FILE" ]; then
echo "⚠ Warning: Log file '$LOG_FILE' does not exist yet."
echo " Waiting for it to be created..."
echo " Waiting for it to be created (will wait up to 30 seconds)..."
echo ""
# Wait for file to be created
for i in {1..30}; do
if [ -f "$LOG_FILE" ]; then
echo "✓ Log file created"
break
fi
sleep 1
done
if [ ! -f "$LOG_FILE" ]; then
echo "❌ Log file still doesn't exist after 30 seconds"
echo " Make sure the server is running: ./rebuild.sh prod"
exit 1
fi
fi
tail -f "$LOG_FILE" 2>/dev/null | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:|INFO.*Activity:"
tail -f "$LOG_FILE" 2>/dev/null | grep -E "\[ACTIVITY\]|\[PHOTO_UPLOAD\]|\[GUESS_SUBMIT\]|Activity:|INFO.*Activity:" || {
echo "⚠ No activity logs found. Make sure:"
echo " 1. Server is running"
echo " 2. LOG_LEVEL is set to INFO or DEBUG"
echo " 3. Users are actually using the site"
}
elif systemctl is-active --quiet app-backend 2>/dev/null; then
# Use systemd journal if service is active
echo "Using systemd journal (app-backend service)"