| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- @echo off
- chcp 65001 > nul
- echo ========================================
- echo MQTT Project Deployment to Server
- echo ========================================
- echo.
- echo Step 1: Check server connection...
- ping 192.168.1.17 -n 2 > nul
- if %errorlevel% equ 0 (
- echo Server connection OK
- ) else (
- echo Server connection failed
- exit /b 1
- )
- echo.
- echo Step 2: Create directory structure on server...
- ssh yangfei@192.168.1.17 "mkdir -p /home/yangfei/mqtt-vue-dashboard/backend"
- ssh yangfei@192.168.1.17 "mkdir -p /home/yangfei/mqtt-vue-dashboard/frontend"
- ssh yangfei@192.168.1.17 "mkdir -p /home/yangfei/mqtt-vue-dashboard/logs"
- echo Directories created
- echo.
- echo Step 3: Build frontend project...
- cd mqtt-vue-dashboard
- if exist node_modules (
- echo Frontend dependencies exist, skipping install
- ) else (
- echo Installing frontend dependencies...
- call npm install
- if %errorlevel% neq 0 (
- echo Frontend dependency installation failed
- exit /b 1
- )
- )
- echo Building frontend...
- call npm run build
- if %errorlevel% neq 0 (
- echo Frontend build failed
- exit /b 1
- )
- echo.
- echo Step 4: Upload frontend files to server...
- if exist dist (
- scp -r dist yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/frontend/
- if %errorlevel% equ 0 (
- echo Frontend files uploaded successfully
- ) else (
- echo Frontend file upload failed
- exit /b 1
- )
- ) else (
- echo Frontend build directory does not exist
- exit /b 1
- )
- echo.
- echo Step 5: Build backend project...
- cd server
- if exist node_modules (
- echo Backend dependencies exist, skipping install
- ) else (
- echo Installing backend dependencies...
- call npm install
- if %errorlevel% neq 0 (
- echo Backend dependency installation failed
- exit /b 1
- )
- )
- echo Building backend...
- call npm run build
- if %errorlevel% neq 0 (
- echo Backend build failed
- exit /b 1
- )
- echo.
- echo Step 6: Upload backend files to server...
- if exist dist (
- scp -r dist yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/backend/
- echo Backend code uploaded successfully
- )
- if exist package.json (
- scp package.json yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/backend/
- echo Configuration file uploaded successfully
- )
- if exist package-lock.json (
- scp package-lock.json yangfei@192.168.1.17:/home/yangfei/mqtt-vue-dashboard/backend/
- echo Dependency file uploaded successfully
- )
- echo.
- echo Step 7: Install dependencies on server...
- ssh yangfei@192.168.1.17 "cd /home/yangfei/mqtt-vue-dashboard/backend && npm install --production"
- echo Server dependencies installed
- echo.
- echo Step 8: Start backend service...
- ssh yangfei@192.168.1.17 "cd /home/yangfei/mqtt-vue-dashboard/backend && nohup npm start > ../logs/backend.log 2>&1 &"
- echo Backend service started
- echo.
- echo Step 9: Verify deployment...
- ssh yangfei@192.168.1.17 "ls -la /home/yangfei/mqtt-vue-dashboard/frontend/dist/" > nul 2>&1
- if %errorlevel% equ 0 (
- echo Frontend files verified successfully
- ) else (
- echo Frontend file verification failed
- )
- ssh yangfei@192.168.1.17 "ps aux | grep 'node.*backend' | grep -v grep" > nul 2>&1
- if %errorlevel% equ 0 (
- echo Backend service is running normally
- ) else (
- echo Backend service is not running
- )
- echo.
- echo ========================================
- echo Deployment Completed!
- echo ========================================
- echo.
- echo Access Information:
- echo Backend API: http://192.168.1.17:3002
- echo Frontend App: http://192.168.1.17
- echo.
- echo View logs:
- echo ssh yangfei@192.168.1.17 'tail -f /home/yangfei/mqtt-vue-dashboard/logs/backend.log'
- echo.
- pause
|