Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
220 lines
7.6 KiB
Bash
Executable File
220 lines
7.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Load IP configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
|
|
# Complete fix for Blockscout 502 errors
|
|
# Fixes Blockscout service, nginx configuration, and ensures connectivity
|
|
# Usage: Run from Proxmox host: ./fix-blockscout-nginx-complete.sh
|
|
|
|
set -e
|
|
|
|
VMID=5000
|
|
BLOCKSCOUT_PORT=4000
|
|
BLOCKSCOUT_IP="${IP_BLOCKSCOUT}"
|
|
|
|
echo "=========================================="
|
|
echo "Complete Blockscout & Nginx Fix"
|
|
echo "=========================================="
|
|
echo "VMID: $VMID ($BLOCKSCOUT_IP)"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Step 1: Start Blockscout service
|
|
echo "=== Step 1: Starting Blockscout Service ==="
|
|
pct exec $VMID -- systemctl start blockscout.service || true
|
|
pct exec $VMID -- systemctl enable blockscout.service || true
|
|
sleep 5
|
|
|
|
SERVICE_STATUS=$(pct exec $VMID -- systemctl is-active blockscout.service 2>/dev/null || echo "inactive")
|
|
if [ "$SERVICE_STATUS" = "active" ]; then
|
|
echo "✅ Blockscout service started"
|
|
else
|
|
echo "⚠️ Blockscout service may not be running properly"
|
|
echo " Check: pct exec $VMID -- systemctl status blockscout.service"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 2: Wait for Blockscout to be ready
|
|
echo "=== Step 2: Waiting for Blockscout to be ready ==="
|
|
MAX_WAIT=60
|
|
WAITED=0
|
|
while [ $WAITED -lt $MAX_WAIT ]; do
|
|
LOCAL_TEST=$(pct exec $VMID -- curl -s -o /dev/null -w '%{http_code}' --connect-timeout 2 http://127.0.0.1:$BLOCKSCOUT_PORT/api/v2/stats 2>/dev/null || echo "000")
|
|
if [ "$LOCAL_TEST" = "200" ]; then
|
|
echo "✅ Blockscout is ready (HTTP $LOCAL_TEST)"
|
|
break
|
|
fi
|
|
echo -n "."
|
|
sleep 2
|
|
WAITED=$((WAITED + 2))
|
|
done
|
|
echo ""
|
|
|
|
if [ "$LOCAL_TEST" != "200" ]; then
|
|
echo "⚠️ Blockscout may not be fully ready yet (HTTP $LOCAL_TEST)"
|
|
echo " Service may still be starting..."
|
|
fi
|
|
echo ""
|
|
|
|
# Step 3: Ensure nginx configuration is correct
|
|
echo "=== Step 3: Fixing Nginx Configuration ==="
|
|
CONFIG_FILE="/etc/nginx/sites-available/blockscout"
|
|
ENABLED_FILE="/etc/nginx/sites-enabled/blockscout"
|
|
|
|
# Backup existing config
|
|
pct exec $VMID -- bash -c "cp $CONFIG_FILE ${CONFIG_FILE}.backup.$(date +%Y%m%d_%H%M%S) 2>/dev/null || true"
|
|
|
|
# Create correct nginx configuration
|
|
pct exec $VMID -- bash << 'NGINX_FIX'
|
|
CONFIG_FILE="/etc/nginx/sites-available/blockscout"
|
|
cat > "$CONFIG_FILE" << 'NGINX_EOF'
|
|
# HTTP server
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name explorer.d-bis.org ${IP_BLOCKSCOUT:-${IP_DEVICE_14:-${IP_DEVICE_14:-${IP_DEVICE_14:-192.168.11.14}}}0};
|
|
|
|
# API endpoint - MUST come first
|
|
location /api/ {
|
|
proxy_pass http://127.0.0.1:4000/api/;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 300s;
|
|
proxy_connect_timeout 75s;
|
|
add_header Access-Control-Allow-Origin *;
|
|
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
|
|
add_header Access-Control-Allow-Headers "Content-Type";
|
|
}
|
|
|
|
# Health check
|
|
location /health {
|
|
access_log off;
|
|
proxy_pass http://127.0.0.1:4000/api/v2/status;
|
|
proxy_set_header Host $host;
|
|
add_header Content-Type application/json;
|
|
}
|
|
|
|
# Serve custom frontend if exists
|
|
location = / {
|
|
root /var/www/html;
|
|
try_files /index.html /index.html;
|
|
}
|
|
|
|
# Static assets
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
root /var/www/html;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# All other requests proxy to Blockscout
|
|
location / {
|
|
proxy_pass http://127.0.0.1:4000;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_read_timeout 300s;
|
|
proxy_connect_timeout 75s;
|
|
}
|
|
}
|
|
NGINX_EOF
|
|
|
|
# Enable site
|
|
ln -sf "$CONFIG_FILE" /etc/nginx/sites-enabled/blockscout
|
|
rm -f /etc/nginx/sites-enabled/default 2>/dev/null || true
|
|
|
|
echo "✅ Nginx configuration updated"
|
|
NGINX_FIX
|
|
|
|
# Step 4: Test nginx configuration
|
|
echo "=== Step 4: Testing Nginx Configuration ==="
|
|
if pct exec $VMID -- nginx -t 2>&1 | grep -q "test is successful"; then
|
|
echo "✅ Nginx configuration is valid"
|
|
else
|
|
echo "❌ Nginx configuration has errors:"
|
|
pct exec $VMID -- nginx -t 2>&1 | sed 's/^/ /'
|
|
fi
|
|
echo ""
|
|
|
|
# Step 5: Restart nginx
|
|
echo "=== Step 5: Restarting Nginx ==="
|
|
pct exec $VMID -- systemctl restart nginx || true
|
|
sleep 2
|
|
|
|
NGINX_STATUS=$(pct exec $VMID -- systemctl is-active nginx 2>/dev/null || echo "inactive")
|
|
if [ "$NGINX_STATUS" = "active" ]; then
|
|
echo "✅ Nginx restarted successfully"
|
|
else
|
|
echo "⚠️ Nginx may not be running"
|
|
fi
|
|
echo ""
|
|
|
|
# Step 6: Verify connectivity
|
|
echo "=== Step 6: Verifying Connectivity ==="
|
|
|
|
# Test localhost
|
|
LOCAL_TEST=$(pct exec $VMID -- curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://127.0.0.1:$BLOCKSCOUT_PORT/api/v2/stats 2>/dev/null || echo "000")
|
|
if [ "$LOCAL_TEST" = "200" ]; then
|
|
echo "✅ Blockscout API responding on localhost (HTTP $LOCAL_TEST)"
|
|
else
|
|
echo "❌ Blockscout API NOT responding on localhost (HTTP $LOCAL_TEST)"
|
|
echo " This is the root cause of the 502 error!"
|
|
fi
|
|
|
|
# Test via nginx
|
|
NGINX_TEST=$(pct exec $VMID -- curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 http://127.0.0.1/api/v2/stats 2>/dev/null || echo "000")
|
|
if [ "$NGINX_TEST" = "200" ]; then
|
|
echo "✅ Nginx proxy working (HTTP $NGINX_TEST)"
|
|
else
|
|
echo "❌ Nginx proxy NOT working (HTTP $NGINX_TEST)"
|
|
fi
|
|
|
|
# Test external
|
|
EXTERNAL_TEST=$(curl -s -o /dev/null -w '%{http_code}' --connect-timeout 5 "https://explorer.d-bis.org/api/v2/stats" 2>/dev/null || echo "000")
|
|
if [ "$EXTERNAL_TEST" = "200" ]; then
|
|
echo "✅ External API working (HTTP $EXTERNAL_TEST)"
|
|
echo "✅ 502 error is FIXED!"
|
|
elif [ "$EXTERNAL_TEST" = "502" ]; then
|
|
echo "❌ Still getting 502 error"
|
|
if [ "$LOCAL_TEST" != "200" ]; then
|
|
echo ""
|
|
echo "Root cause: Blockscout not responding on localhost:$BLOCKSCOUT_PORT"
|
|
echo ""
|
|
echo "Troubleshooting:"
|
|
echo " 1. Check Blockscout logs: pct exec $VMID -- journalctl -u blockscout.service -n 50"
|
|
echo " 2. Check docker containers: pct exec $VMID -- docker ps"
|
|
echo " 3. Check port: pct exec $VMID -- ss -tlnp | grep :4000"
|
|
fi
|
|
else
|
|
echo "⚠️ External API returned HTTP $EXTERNAL_TEST"
|
|
fi
|
|
echo ""
|
|
|
|
echo "=========================================="
|
|
echo "Summary"
|
|
echo "=========================================="
|
|
echo "Blockscout Service: $SERVICE_STATUS"
|
|
echo "Blockscout Localhost API: $([ "$LOCAL_TEST" = "200" ] && echo "✅ Working" || echo "❌ Not Working")"
|
|
echo "Nginx Proxy: $([ "$NGINX_TEST" = "200" ] && echo "✅ Working" || echo "❌ Not Working")"
|
|
echo "External API: $([ "$EXTERNAL_TEST" = "200" ] && echo "✅ Working" || echo "❌ Not Working ($EXTERNAL_TEST)")"
|
|
echo ""
|
|
|
|
if [ "$EXTERNAL_TEST" != "200" ]; then
|
|
echo "Next steps if still failing:"
|
|
echo " 1. Check Blockscout service: pct exec $VMID -- systemctl status blockscout.service"
|
|
echo " 2. Check Blockscout logs: pct exec $VMID -- journalctl -u blockscout.service -n 100"
|
|
echo " 3. Check docker containers: pct exec $VMID -- docker ps -a"
|
|
echo " 4. Check port 4000: pct exec $VMID -- ss -tlnp | grep :4000"
|
|
echo " 5. Test localhost: pct exec $VMID -- curl -v http://127.0.0.1:4000/api/v2/stats"
|
|
echo ""
|
|
fi |