From c3d4c9cb4b15d85bd58b5f73baf288a97af862be Mon Sep 17 00:00:00 2001 From: DeNNiiInc Date: Sun, 21 Dec 2025 17:07:01 +1100 Subject: [PATCH] Fix CloudSticks setup to handle missing nginx command - Auto-detects nginx binary location - Falls back to systemctl/service commands - Better error handling - More detailed status reporting --- setup-cloudsticks-simple.sh | 106 +++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 37 deletions(-) diff --git a/setup-cloudsticks-simple.sh b/setup-cloudsticks-simple.sh index 333cf48..e2ae280 100644 --- a/setup-cloudsticks-simple.sh +++ b/setup-cloudsticks-simple.sh @@ -1,11 +1,10 @@ #!/bin/bash -# Simple CloudSticks Nginx Proxy Setup -# Adds proxy config to http block +# CloudSticks Nginx Setup - Handles custom nginx paths set -e -echo "🔧 CloudSticks Nginx Proxy Setup (Simple Method)" -echo "=================================================" +echo "🔧 CloudSticks Nginx Proxy Setup" +echo "=================================" echo "" GREEN='\033[0;32m' @@ -25,28 +24,22 @@ cp "$CONFIG_FILE" "${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S)" echo -e "${GREEN}✅ Backup created${NC}" echo "" -echo "Step 2: Adding proxy configuration..." +echo "Step 2: Creating proxy configuration..." +mkdir -p /etc/nginx-cs/conf.d -# Create a separate config file for Connect-5 cat > /etc/nginx-cs/conf.d/connect5-proxy.conf << 'EOF' # Connect-5 Proxy Configuration server { listen 443 ssl; server_name connect5.beyondcloud.technology; - # SSL certificates (CloudSticks should handle these) - # ssl_certificate and ssl_certificate_key are managed by CloudSticks - - # Root directory root /home/github2/apps/app-connect5; index index.html; - # Serve static files location / { try_files $uri $uri/ /index.html; } - # Proxy API requests to Node.js location /api { proxy_pass http://localhost:3000; proxy_http_version 1.1; @@ -59,7 +52,6 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } - # Proxy Socket.io WebSocket requests location /socket.io { proxy_pass http://localhost:3000; proxy_http_version 1.1; @@ -74,58 +66,98 @@ server { } EOF -echo -e "${GREEN}✅ Proxy config created at /etc/nginx-cs/conf.d/connect5-proxy.conf${NC}" +echo -e "${GREEN}✅ Proxy config created${NC}" echo "" -echo "Step 3: Testing Nginx configuration..." -if nginx -t 2>&1 | grep -q "successful\|syntax is ok"; then - echo -e "${GREEN}✅ Config valid${NC}" +echo "Step 3: Finding nginx command..." +NGINX_CMD="" +if command -v nginx &> /dev/null; then + NGINX_CMD="nginx" +elif [ -f "/usr/sbin/nginx" ]; then + NGINX_CMD="/usr/sbin/nginx" +elif [ -f "/usr/local/sbin/nginx" ]; then + NGINX_CMD="/usr/local/sbin/nginx" +elif [ -f "/opt/cloudsticks/nginx/sbin/nginx" ]; then + NGINX_CMD="/opt/cloudsticks/nginx/sbin/nginx" else - echo -e "${RED}❌ Config error${NC}" - nginx -t - echo "" - echo "Restoring backup..." - rm /etc/nginx-cs/conf.d/connect5-proxy.conf 2>/dev/null || true - exit 1 + echo -e "${YELLOW}⚠️ Could not find nginx command${NC}" + echo "Trying to reload via systemctl..." +fi + +if [ -n "$NGINX_CMD" ]; then + echo "Testing config with: $NGINX_CMD" + if $NGINX_CMD -t 2>&1 | grep -q "successful\|syntax is ok"; then + echo -e "${GREEN}✅ Config valid${NC}" + else + echo -e "${RED}❌ Config error${NC}" + $NGINX_CMD -t + rm /etc/nginx-cs/conf.d/connect5-proxy.conf + exit 1 + fi fi echo "" echo "Step 4: Reloading Nginx..." -systemctl reload nginx 2>/dev/null || service nginx reload 2>/dev/null || nginx -s reload -echo -e "${GREEN}✅ Nginx reloaded${NC}" +if systemctl reload nginx 2>/dev/null; then + echo -e "${GREEN}✅ Reloaded via systemctl${NC}" +elif service nginx reload 2>/dev/null; then + echo -e "${GREEN}✅ Reloaded via service${NC}" +elif [ -n "$NGINX_CMD" ]; then + $NGINX_CMD -s reload 2>/dev/null && echo -e "${GREEN}✅ Reloaded via nginx -s${NC}" || echo -e "${YELLOW}⚠️ Could not reload${NC}" +else + echo -e "${YELLOW}⚠️ Please restart nginx manually${NC}" + echo "Try: systemctl restart nginx" +fi echo "" echo "Step 5: Checking Node.js..." if pgrep -f "node server.js" > /dev/null; then - echo -e "${GREEN}✅ Node.js running${NC}" + PID=$(pgrep -f "node server.js") + echo -e "${GREEN}✅ Node.js running (PID: $PID)${NC}" else echo -e "${YELLOW}⚠️ Starting Node.js...${NC}" cd /home/github2/apps/app-connect5 nohup node server.js > server.log 2>&1 & sleep 2 - echo -e "${GREEN}✅ Node.js started${NC}" + if pgrep -f "node server.js" > /dev/null; then + echo -e "${GREEN}✅ Node.js started${NC}" + fi fi echo "" -echo "Step 6: Testing..." -sleep 2 +echo "Step 6: Testing endpoints..." +sleep 3 LOCAL=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000/api/db-status 2>/dev/null || echo "000") -PROD=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null || echo "000") +echo "Local (localhost:3000): HTTP $LOCAL" -echo "Local endpoint: HTTP $LOCAL" -echo "Production endpoint: HTTP $PROD" +if [ "$LOCAL" = "200" ]; then + echo -e "${GREEN}✅ Node.js server is responding${NC}" +fi + +PROD=$(curl -s -o /dev/null -w "%{http_code}" https://connect5.beyondcloud.technology/api/db-status 2>/dev/null || echo "000") +echo "Production: HTTP $PROD" if [ "$PROD" = "200" ]; then + echo -e "${GREEN}✅ Production is working!${NC}" echo "" - echo -e "${GREEN}✅ SUCCESS! Production is working!${NC}" - echo "" - curl -s https://connect5.beyondcloud.technology/api/db-status | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status + echo "Database Status:" + curl -s https://connect5.beyondcloud.technology/api/db-status 2>/dev/null | python3 -m json.tool 2>/dev/null || curl -s https://connect5.beyondcloud.technology/api/db-status +elif [ "$PROD" = "502" ]; then + echo -e "${YELLOW}⚠️ 502 Bad Gateway - Nginx is proxying but Node.js might not be ready${NC}" +elif [ "$PROD" = "404" ]; then + echo -e "${YELLOW}⚠️ 404 - Nginx might need manual restart${NC}" + echo "Try: sudo systemctl restart nginx" fi echo "" -echo "=================================================" +echo "=================================" echo -e "${GREEN}🎉 Setup Complete!${NC}" echo "" +echo "Config file: /etc/nginx-cs/conf.d/connect5-proxy.conf" echo "Visit: https://connect5.beyondcloud.technology/" -echo "=================================================" +echo "" +echo "If not working, try:" +echo " sudo systemctl restart nginx" +echo " tail -f /home/github2/apps/app-connect5/server.log" +echo "================================="