fix_nginx_final.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. SERVER_IP="47.253.147.187"
  3. SERVER_USER="root"
  4. SERVER_PASS="5H0FuZ:2s0q)Lx"
  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:/www/server/panel/vhost/nginx/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 "/etc/init.d/nginx reload\r"
  28. # Check Node App
  29. send "echo '--- CHECKING NODE APP ---'\r"
  30. send "cd /www/wwwroot/ccdw-website/server\r"
  31. # Force install production deps again just in case
  32. send "npm install --omit=dev --registry=https://registry.npmmirror.com\r"
  33. send "pm2 restart ccdw-server\r"
  34. send "sleep 3\r"
  35. send "pm2 list\r"
  36. send "pm2 logs ccdw-server --lines 20 --nostream\r"
  37. # Check ports again
  38. send "netstat -tulpn | grep 3001\r"
  39. send "exit\r"
  40. expect eof
  41. EOF