deploy.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. npx vite build
  3. # 开发主机(开发环境服务器 有SSH权限至生产环境)
  4. DEV_HOST=root@dbo.fmode.cn
  5. # 生产主机(生产环境服务器)
  6. PROD_HOST=root@8.140.98.43
  7. # PROD_HOST=root@123.57.204.89
  8. # 部署路径
  9. DIR_SERVER=/opt/edu-textbook-server
  10. # 资源文件
  11. cp -rf config dist/server/
  12. cp package.json dist/server/
  13. sed -i '/@embedded/d' dist/server/package.json
  14. sed -i '/@embedded/d' dist/server/package.json
  15. cp config.js dist/server/
  16. cp keepalive.js dist/server/
  17. cp -rf cloud/tbook/template dist/server/
  18. cd dist
  19. tar zcvf server.tar.gz ./server
  20. cp server.tar.gz ../../docker/opt/
  21. cd ..
  22. # 压缩部署
  23. ssh $DEV_HOST "mkdir -p $DIR_SERVER"
  24. scp dist/server.tar.gz $DEV_HOST:$DIR_SERVER/
  25. ssh $DEV_HOST "scp -r $DIR_SERVER/server.tar.gz $PROD_HOST:/opt/"
  26. ssh $DEV_HOST "ssh $PROD_HOST \"cd /opt/ && tar zxvf server.tar.gz && mkdir -p edu-textbook-server && cp -rf server/* edu-textbook-server/\"" # 仅安装prod
  27. ssh $DEV_HOST "ssh $PROD_HOST \"cd /opt/ && cp server.tar.gz /var/www/edu-textbook\"" # 仅安装prod
  28. # 部署过程
  29. # ssh $DEV_HOST "mkdir -p $DIR_SERVER"
  30. # scp dist/server/server.js $DEV_HOST:$DIR_SERVER/
  31. # scp ./package.json $DEV_HOST:$DIR_SERVER/
  32. # scp ./config.js $DEV_HOST:$DIR_SERVER/
  33. # ssh $DEV_HOST "scp -r $DIR_SERVER $PROD_HOST:/opt/"
  34. # 启动过程
  35. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && ls -lah\"" # 仅安装prod
  36. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && npm i --omit=dev --force\"" # 仅安装prod
  37. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && pm2 stop server server2 server3 server4 server5 server6 server7 server8\""
  38. ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && pm2 start server server2 server3 server4 server5 server6 server7 server8\""
  39. # ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && pm2 stop server.js\""
  40. # ssh $DEV_HOST "ssh $PROD_HOST \"cd $DIR_SERVER && pm2 start server.js\""
  41. # pm2 start -f --name=server1 server.js -- --port=61337
  42. # pm2 start -f --name=server2 server.js -- --port=61338
  43. # pm2 start -f --name=server3 server.js -- --port=61339
  44. # pm2 start -f --name=server4 server.js -- --port=61340
  45. # pm2 start -f --name=server5 server.js -- --port=61341
  46. # pm2 start -f --name=server6 server.js -- --port=61342
  47. # pm2 start -f --name=server7 server.js -- --port=61343
  48. # pm2 start -f --name=server8 server.js -- --port=61344