100 lines
2.5 KiB
Bash
Executable File
100 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tilbudgivern Application Startup Script
|
|
# This script starts the complete application stack
|
|
|
|
set -e
|
|
|
|
echo "🚀 Starting Tilbudgivern Application Stack..."
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
success() { echo -e "${GREEN}✅ $1${NC}"; }
|
|
warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
|
|
error() { echo -e "${RED}❌ $1${NC}"; exit 1; }
|
|
|
|
# Check if running as correct user
|
|
if [ "$EUID" -eq 0 ]; then
|
|
error "Please run this script as a regular user, not as root"
|
|
fi
|
|
|
|
# Change to application directory
|
|
cd /mnt/HC_Volume_103713257/tilbudgivern
|
|
|
|
echo "🔍 Checking application components..."
|
|
|
|
# Check database
|
|
if mysql -u tilbudgivern_service -p"${DB_PASSWORD}" -e "USE tilbudgivern; SELECT 'OK' as status;" &>/dev/null; then
|
|
success "Database connection OK"
|
|
else
|
|
error "Database connection failed"
|
|
fi
|
|
|
|
# Check nginx
|
|
if sudo systemctl is-active nginx &>/dev/null; then
|
|
success "Nginx is running"
|
|
else
|
|
warning "Starting nginx..."
|
|
sudo systemctl start nginx || error "Failed to start nginx"
|
|
success "Nginx started"
|
|
fi
|
|
|
|
# Check frontend build
|
|
if [ -f "frontend/build/index.html" ]; then
|
|
success "Frontend build exists"
|
|
else
|
|
warning "Frontend needs to be built"
|
|
echo "Building frontend..."
|
|
cd frontend
|
|
npm run build || error "Frontend build failed"
|
|
cd ..
|
|
success "Frontend built successfully"
|
|
fi
|
|
|
|
# Start/restart backend with PM2
|
|
echo "🔧 Managing backend service..."
|
|
if pm2 describe tilbudgivern-app &>/dev/null; then
|
|
echo "Restarting existing PM2 process..."
|
|
pm2 restart tilbudgivern-app
|
|
else
|
|
echo "Starting new PM2 process..."
|
|
pm2 start unified-server.js --name tilbudgivern-app
|
|
fi
|
|
|
|
success "Backend service running"
|
|
|
|
# Verify everything is working
|
|
echo "🧪 Running health checks..."
|
|
|
|
sleep 3 # Give services time to start
|
|
|
|
# Check frontend
|
|
if curl -s http://localhost | grep -q "html"; then
|
|
success "Frontend is accessible"
|
|
else
|
|
error "Frontend health check failed"
|
|
fi
|
|
|
|
# Check backend API
|
|
if curl -s http://localhost/api/health | grep -q "status"; then
|
|
success "Backend API is responding"
|
|
else
|
|
warning "Backend API might be starting up..."
|
|
fi
|
|
|
|
# Show PM2 status
|
|
echo "📊 Application Status:"
|
|
pm2 list
|
|
|
|
echo ""
|
|
success "🎉 Tilbudgivern Application Stack is running!"
|
|
echo " 🌐 Frontend: http://localhost"
|
|
echo " 🔗 API: http://localhost/api/"
|
|
echo " 📊 Status: pm2 monit"
|
|
echo ""
|
|
echo "To stop the application: pm2 stop tilbudgivern-app"
|
|
echo "To view logs: pm2 logs tilbudgivern-app --no-stream" |