| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/bin/bash
- SERVER_IP="47.253.147.187"
- SERVER_USER="root"
- SERVER_PASS="5H0FuZ:2s0q)Lx"
- NODE_BIN="/www/server/nodejs/v22.16.0/bin"
- /usr/bin/expect <<EOF
- set timeout 180
- spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP
- expect {
- "password:" { send "$SERVER_PASS\r" }
- "yes/no" { send "yes\r"; exp_continue }
- }
- expect "#"
- # 1. Link Node binaries
- send "echo '--- LINKING NODE BINARIES ---'\r"
- send "ln -sf $NODE_BIN/node /usr/bin/node\r"
- send "ln -sf $NODE_BIN/npm /usr/bin/npm\r"
- send "ln -sf $NODE_BIN/npx /usr/bin/npx\r"
- # 2. Finish backend deployment
- send "echo '--- FINISHING BACKEND DEPLOYMENT ---'\r"
- send "cd /www/wwwroot/ccdw-website/server\r"
- send "npm install --omit=dev --registry=https://registry.npmmirror.com\r"
- send "npm install -g pm2 --registry=https://registry.npmmirror.com\r"
- # Link PM2
- send "ln -sf $NODE_BIN/pm2 /usr/bin/pm2\r"
- # Start App
- send "echo '--- STARTING APP ---'\r"
- send "pm2 delete ccdw-server 2>/dev/null\r"
- send "pm2 start index.js --name ccdw-server\r"
- send "pm2 save\r"
- # 3. Create Nginx Config (HTTP)
- send "echo '--- CREATING NGINX CONFIG ---'\r"
- send "cat > /www/server/panel/vhost/nginx/ccdw.xyz.conf <<ENDCONF
- server {
- listen 80;
- server_name ccdw.xyz www.ccdw.xyz;
-
- access_log /www/wwwlogs/ccdw.xyz.log;
- error_log /www/wwwlogs/ccdw.xyz.error.log;
- location / {
- proxy_pass http://127.0.0.1:3001;
- 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;
- }
- }
- ENDCONF\r"
- # 4. Reload Nginx
- send "echo '--- RELOADING NGINX ---'\r"
- send "nginx -t\r"
- # 宝塔环境下 reload 命令
- send "/etc/init.d/nginx reload\r"
- # 5. Check URL access
- send "echo '--- CHECKING ACCESS ---'\r"
- send "curl -I http://127.0.0.1:3001\r"
- send "curl -I -H 'Host: ccdw.xyz' http://127.0.0.1\r"
- send "exit\r"
- expect eof
- EOF
|