This system provides robust, reliable startup and shutdown for all environments:
- ✅ TEST: Fast startup, clean state between tests
- ✅ DEV: Hot reload, preserve state for development
- ✅ QA: Production-like setup with monitoring
- ✅ PROD: Graceful shutdown, zero-downtime deployments
# Development environment (default)
mise run startup
# Specific environment
mise run startup-dev # Development
mise run startup-test # Testing
mise run startup-qa # QA/Staging# Graceful shutdown (keep database)
mise run shutdown
# Force shutdown (ignore errors)
mise run shutdown-force
# Complete shutdown (stop database too)
mise run shutdown-clean# Quick health check
mise run health
# View status
mise run status
# Full system status
mise run health-full# Restart services (keep database)
mise run restart
# Clean restart (reset everything)
mise run restart-cleanWhat it does:
-
Prerequisites Check
- Verifies Node.js, pnpm, Docker installed
- Checks database connectivity
- Validates environment configuration
-
Port Cleanup
- Kills processes on ports 3000, 3001, 3003
- Ensures clean state before startup
- Handles orphaned processes
-
Service Startup (in order)
- Database (PostgreSQL, Redis)
- Backend services (auth, CRM)
- API Gateway
- Frontend
-
Health Checks
- Waits for each service to be ready
- Retries with exponential backoff
- Verifies endpoints return 200 OK
-
Logging
- All output logged to
tmp/logs/startup-*.log - PID files saved for each service
- Success marker created
- All output logged to
Features:
- ⏱️ Timeout handling: Max 60s per service
- 🔄 Retry logic: 30 retries with 2s interval
- 📊 Response time tracking: Logs startup duration
- 🚨 Error recovery: Graceful failure with cleanup
- 📝 Detailed logging: Every step recorded
What it does:
-
Graceful Shutdown
- Sends SIGTERM to all services
- Waits 10s for graceful exit
- Force kills if timeout exceeded
-
Service Order (reverse of startup)
- Frontend (user-facing, stop first)
- API Gateway
- Backend services (CRM, auth)
- Database (optional, preserve data)
-
Resource Cleanup
- Removes PID files
- Cleans up success markers
- Kills orphaned processes
- Frees all ports
-
Verification
- Checks all ports are free
- Verifies no processes remain
- Logs any cleanup issues
Features:
- ⏱️ Graceful timeout: 10s before force kill
- 🔍 Verification: Ensures complete shutdown
- 🧹 Cleanup: Removes all traces
- 📊 Port scanning: Detects orphaned processes
- 📝 Logging: All actions recorded
What it does:
-
Service Health
- Tests HTTP endpoints
- Measures response time
- Reports status with color codes
-
Database Connectivity
- PostgreSQL port check
- Redis port check
-
Summary Report
- Total services healthy/unhealthy
- Response times
- Exit code (0 = healthy, 1 = unhealthy)
Features:
- ⚡ Fast: Tests all services in parallel
- 📊 Response times: Millisecond precision
- 🎨 Color output: Green = OK, Red = Failed
- 🔄 Exit codes: Perfect for CI/CD
# Morning: Start development
mise run startup-dev
# Work on code (services auto-reload)
# ...
# Lunch: Stop services
mise run shutdown
# Afternoon: Resume work
mise run startup-dev
# Evening: Complete shutdown
mise run shutdown-clean# Start test environment
mise run startup-test
# Run E2E tests
mise run test-file-upload-ui-headed
# Test complete, shutdown
mise run shutdown
# Run again with clean state
mise run restart-clean
mise run test-file-upload-ui# Pre-deployment health check
mise run health
# → Ensure all services healthy
# Graceful restart (zero downtime)
mise run restart
# → Services restarted one by one
# Post-deployment verification
mise run health
mise run status# Services won't start?
mise run shutdown-force # Force kill everything
mise run startup # Try again
# Port conflicts?
mise run shutdown-clean # Kill all + cleanup
lsof -ti:3000,3001,3003 # Check ports manually
mise run startup # Restart
# Check logs
mise run logs-startup # View startup logs
mise run logs-shutdown # View shutdown logs
tail -f tmp/logs/*.log # Watch all logsscripts/startup.sh- Main startup scriptscripts/shutdown.sh- Main shutdown scriptscripts/health-check.sh- Health check script
tmp/logs/startup-*.log- Startup logs (timestamped)tmp/logs/shutdown-*.log- Shutdown logs (timestamped)tmp/logs/auth-service.log- Auth service outputtmp/logs/crm-service.log- CRM service outputtmp/logs/frontend.log- Frontend output
tmp/logs/auth-service.pid- Auth service PIDtmp/logs/crm-service.pid- CRM service PIDtmp/logs/frontend.pid- Frontend PID
tmp/logs/.startup-success- Marker for successful startup
# Set environment
export NEXO_ENV=dev # or test, qa, prod
# Database connection
export DATABASE_URL="postgresql://user:pass@localhost:5432/nexo"
# Service ports (auto-detected)
export AUTH_PORT=3001
export CRM_PORT=3003
export FRONTEND_PORT=3000Edit in script files:
# startup.sh
MAX_RETRIES=30 # Health check retries
RETRY_INTERVAL=2 # Seconds between retries
# shutdown.sh
GRACEFUL_TIMEOUT=10 # Graceful shutdown timeout
FORCE_TIMEOUT=5 # Force kill timeout$ mise run health
============================================================================
NEXO CRM - Health Check
2026-02-07 23:45:30
============================================================================
Services:
✓ Auth Service (156ms)
✓ CRM Service (142ms)
✓ API Gateway (98ms)
✓ Frontend (234ms)
Databases:
✓ PostgreSQL (port 5432)
✓ Redis (port 6379)
============================================================================
✓ All services healthy0- Success, all services started1- Prerequisites check failed2- Port cleanup failed3- Database startup failed4- Backend services failed5- Frontend startup failed6- System verification failed
0- Success, all services stopped1- Shutdown verification failed2- Force shutdown required
0- All services healthy1- One or more services unhealthy
Symptom: startup.sh fails with timeout errors
Solution:
# 1. Force cleanup
mise run shutdown-force
# 2. Check ports manually
lsof -ti:3000,3001,3003,5432
# Kill any processes: kill -9 <PID>
# 3. Restart
mise run startupSymptom: shutdown.sh takes too long
Solution:
# Use force shutdown
mise run shutdown-force
# Or clean everything
mise run shutdown-cleanSymptom: "Port already in use" errors
Solution:
# Check what's using the port
lsof -ti:3001
# Kill the process
kill -9 <PID>
# Or let startup script handle it
mise run startup # Auto-cleanup enabledSymptom: "Database not accessible" errors
Solution:
# Start database manually
docker compose -f docker/docker-compose.yml up -d postgres
# Wait for it to be ready
sleep 10
# Then start services
mise run startup❌ DON'T:
# Manual start (error-prone)
cd nexo-prj
pnpm nx serve auth-service &
pnpm nx serve crm-service &
pnpm nx serve nexo-prj &
# Hope nothing went wrong...✅ DO:
# Robust startup
mise run startup
# Automatic health checks + logging# Always verify system is ready
mise run health
# Then run tests
mise run test-file-upload-ui# Run test
mise run test-e2e
# Clean shutdown
mise run shutdown
# Clean startup for next test
mise run startup-test# Development
NEXO_ENV=dev mise run startup
# Testing (faster, cleaner)
NEXO_ENV=test mise run startup
# Production (external database)
NEXO_ENV=prod mise run startup# Watch startup in real-time
tail -f tmp/logs/startup-*.log
# Check for errors
grep ERROR tmp/logs/startup-*.logjobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup
run: |
mise install
mise run test-install
- name: Start Services
run: |
NEXO_ENV=test mise run startup
- name: Health Check
run: |
mise run health
- name: Run Tests
run: |
mise run test-e2e
- name: Shutdown
if: always()
run: |
mise run shutdown-force
- name: Upload Logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: logs
path: tmp/logs/With this system, you get:
- ✅ Reliable startup: Prerequisites check, port cleanup, health verification
- ✅ Graceful shutdown: SIGTERM first, force kill if needed
- ✅ Health monitoring: Quick status checks with response times
- ✅ Detailed logging: Every step recorded for debugging
- ✅ Environment support: TEST, DEV, QA, PROD configurations
- ✅ Error recovery: Automatic cleanup and retry logic
- ✅ Zero manual intervention: One command to start/stop everything
No more:
- ❌ Port conflicts
- ❌ Orphaned processes
- ❌ Manual service management
- ❌ "It works on my machine"
- ❌ Guessing if services are ready
Start using it now:
mise run startup # That's it!