fix_nginx_final.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. SERVER_IP="45.61.60.10"
  3. SERVER_USER="root"
  4. SERVER_PASS="UQb9TgSwC@vwhEM"
  5. # 1. Upload Nginx config
  6. /usr/bin/expect <<EOF
  7. set timeout 30
  8. spawn scp -o StrictHostKeyChecking=no ccdw.xyz.conf $SERVER_USER@$SERVER_IP:/etc/nginx/sites-available/ccdw.xyz.conf
  9. expect {
  10. "password:" { send "$SERVER_PASS\r" }
  11. "yes/no" { send "yes\r"; exp_continue }
  12. }
  13. expect eof
  14. EOF
  15. # 2. SSH actions
  16. /usr/bin/expect <<EOF
  17. set timeout 60
  18. spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP
  19. expect {
  20. "password:" { send "$SERVER_PASS\r" }
  21. "yes/no" { send "yes\r"; exp_continue }
  22. }
  23. expect "#"
  24. # Reload Nginx
  25. send "echo '--- RELOADING NGINX STATUS ---'\r"
  26. send "nginx -t\r"
  27. send "ln -sf /etc/nginx/sites-available/ccdw.xyz.conf /etc/nginx/sites-enabled/ccdw.xyz.conf\r"
  28. send "systemctl reload nginx\r"
  29. # Check Node App
  30. send "echo '--- CHECKING NODE APP ---'\r"
  31. send "cd /var/www/ccdw-website/server\r"
  32. # Force install production deps again just in case
  33. send "npm install --omit=dev --registry=https://registry.npmmirror.com\r"
  34. send "pm2 restart ccdw-server\r"
  35. send "sleep 3\r"
  36. send "pm2 list\r"
  37. send "pm2 logs ccdw-server --lines 20 --nostream\r"
  38. # Check ports again
  39. send "netstat -tulpn | grep 3001\r"
  40. send "exit\r"
  41. expect eof
  42. EOF