Files
yuyueguahao/scripts/deploy-hospitalimg.exp
2026-07-05 14:43:34 +08:00

57 lines
1.8 KiB
Plaintext
Executable File

#!/usr/bin/expect -f
# 部署 hospitalImage 模块 + admin 更新到 124.221.67.199
# 用法: expect deploy-hospitalimg.exp
set timeout 60
set password "Szgt888."
set host "124.221.67.199"
set user "root"
set remote_dir "/opt/yuyueguahao"
# 1. 上传后端新文件 (hospitalImage + upload + seed + index.js + modules/index.js + schema.sql)
puts "\n>>> STEP 1: 上传后端新文件..."
foreach f {
server/src/modules/hospitalImage
server/src/modules/upload
server/src/seeds/hospitalImages.js
server/src/modules/index.js
server/src/index.js
server/src/schema.sql
} {
spawn scp -r $f ${user}@${host}:${remote_dir}/$f
expect {
"password:" { send "$password\r" }
"yes/no" { send "yes\r"; exp_continue }
}
expect eof
}
# 2. 上传 admin 更新
puts "\n>>> STEP 2: 上传 admin 更新..."
spawn scp admin/app.js admin/index.html ${user}@${host}:${remote_dir}/admin/
expect {
"password:" { send "$password\r" }
"yes/no" { send "yes\r"; exp_continue }
}
expect eof
# 3. 重启 PM2
puts "\n>>> STEP 3: 重启 PM2..."
spawn ssh ${user}@${host} "cd ${remote_dir}/server && pm2 restart yuyueguahao-api 2>&1; sleep 3; pm2 list 2>&1 | head -10"
expect {
"password:" { send "$password\r" }
"yes/no" { send "yes\r"; exp_continue }
}
expect eof
# 4. 验证接口
puts "\n>>> STEP 4: 验证接口..."
spawn ssh ${user}@${host} "curl -s 'http://localhost:3000/api/v1/hospital-images?enabled=true' && echo '' && echo '---uploads---' && curl -s -X POST http://localhost:3000/api/v1/uploads/image -H 'Content-Type: application/json' -H 'Authorization: Bearer xxx' -d '{\"url\":\"https://picsum.photos/200\"}'"
expect {
"password:" { send "$password\r" }
"yes/no" { send "yes\r"; exp_continue }
}
expect eof
puts "\n>>> DEPLOY DONE"