deploy-simple.bat 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. @echo off
  2. chcp 65001 > nul
  3. echo ========================================
  4. echo MQTT Project Deployment to Server
  5. echo ========================================
  6. echo.
  7. echo Step 1: Check server connection...
  8. ping 192.168.1.17 -n 2 > nul
  9. if %errorlevel% equ 0 (
  10. echo Server connection OK
  11. ) else (
  12. echo Server connection failed
  13. exit /b 1
  14. )
  15. echo.
  16. echo Step 2: Create directory structure on server...
  17. ssh yangfei@192.168.1.17 "mkdir -p /home/yangfei/mqtt-vue-dashboard/backend"
  18. ssh yangfei@192.168.1.17 "mkdir -p /home/yangfei/mqtt-vue-dashboard/frontend"
  19. ssh yangfei@192.168.1.17 "mkdir -p /home/yangfei/mqtt-vue-dashboard/logs"
  20. echo Directories created
  21. echo.
  22. echo Step 3: Build frontend project...
  23. cd mqtt-vue-dashboard
  24. if exist node_modules (
  25. echo Frontend dependencies exist, skipping install
  26. ) else (
  27. echo Installing frontend dependencies...
  28. call npm install
  29. if %errorlevel% neq 0 (
  30. echo Frontend dependency installation failed
  31. exit /b 1
  32. )
  33. )
  34. echo Building frontend...
  35. call npm run build
  36. if %errorlevel% neq 0 (
  37. echo Frontend build failed
  38. exit /b 1
  39. )
  40. echo.
  41. echo Step 4: Upload frontend files to server...
  42. if exist dist (
  43. scp -r dist yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/frontend/
  44. if %errorlevel% equ 0 (
  45. echo Frontend files uploaded successfully
  46. ) else (
  47. echo Frontend file upload failed
  48. exit /b 1
  49. )
  50. ) else (
  51. echo Frontend build directory does not exist
  52. exit /b 1
  53. )
  54. echo.
  55. echo Step 5: Build backend project...
  56. cd server
  57. if exist node_modules (
  58. echo Backend dependencies exist, skipping install
  59. ) else (
  60. echo Installing backend dependencies...
  61. call npm install
  62. if %errorlevel% neq 0 (
  63. echo Backend dependency installation failed
  64. exit /b 1
  65. )
  66. )
  67. echo Building backend...
  68. call npm run build
  69. if %errorlevel% neq 0 (
  70. echo Backend build failed
  71. exit /b 1
  72. )
  73. echo.
  74. echo Step 6: Upload backend files to server...
  75. if exist dist (
  76. scp -r dist yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/backend/
  77. echo Backend code uploaded successfully
  78. )
  79. if exist package.json (
  80. scp package.json yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/backend/
  81. echo Configuration file uploaded successfully
  82. )
  83. if exist package-lock.json (
  84. scp package-lock.json yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/backend/
  85. echo Dependency file uploaded successfully
  86. )
  87. echo.
  88. echo Step 7: Install dependencies on server...
  89. ssh yangfei@192.168.1.17 "cd /home/yangfei/mqtt-vue-dashboard/backend && npm install --production"
  90. echo Server dependencies installed
  91. echo.
  92. echo Step 8: Start backend service...
  93. ssh yangfei@192.168.1.17 "cd /home/yangfei/mqtt-vue-dashboard/backend && nohup npm start > ../logs/backend.log 2>&1 &"
  94. echo Backend service started
  95. echo.
  96. echo Step 9: Verify deployment...
  97. ssh yangfei@192.168.1.17 "ls -la /home/yangfei/mqtt-vue-dashboard/frontend/dist/" > nul 2>&1
  98. if %errorlevel% equ 0 (
  99. echo Frontend files verified successfully
  100. ) else (
  101. echo Frontend file verification failed
  102. )
  103. ssh yangfei@192.168.1.17 "ps aux | grep 'node.*backend' | grep -v grep" > nul 2>&1
  104. if %errorlevel% equ 0 (
  105. echo Backend service is running normally
  106. ) else (
  107. echo Backend service is not running
  108. )
  109. echo.
  110. echo ========================================
  111. echo Deployment Completed!
  112. echo ========================================
  113. echo.
  114. echo Access Information:
  115. echo Backend API: http://192.168.1.17:3002
  116. echo Frontend App: http://192.168.1.17
  117. echo.
  118. echo View logs:
  119. echo ssh yangfei@192.168.1.17 'tail -f /home/yangfei/mqtt-vue-dashboard/logs/backend.log'
  120. echo.
  121. pause