diff --git a/backend/ecosystem.config.js b/backend/ecosystem.config.js deleted file mode 100644 index a822957..0000000 --- a/backend/ecosystem.config.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - apps: [ - { - name: "signaling-server", - script: "./dist/server.js", // Point to the compiled file - watch: false, - env: { - NODE_ENV: "production", - BACKEND_PORT: 3001, - }, - log_date_format: "YYYY-MM-DD HH:mm:ss", - error_file: "/var/log/signaling-server-error.log", - out_file: "/var/log/signaling-server-out.log", - max_memory_restart: "500M", - instances: 1, - exec_mode: "fork", - group: "ssl-cert", // Add this line to specify the group the process runs as - }, - ], -}; diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 0efc45c..fcce5ec 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -247,7 +247,7 @@ With the unified SSL certificate obtained, we can now complete the production co ### 4.6. Run the Application with PM2 -PM2 is a powerful process manager for Node.js. We will use it to run the backend and frontend services separately. +PM2 is a powerful process manager for Node.js. We will use it to run both backend and frontend services. 1. **Install PM2 globally:** @@ -255,33 +255,24 @@ PM2 is a powerful process manager for Node.js. We will use it to run the backend sudo npm install -g pm2 ``` -2. **Start the Backend Service:** - The backend directory provides an `ecosystem.config.js` file for PM2. +2. **Start Services Using Unified Configuration:** + + The project root directory provides a unified `ecosystem.config.js` configuration file that can start all services at once: ```bash - cd backend - # If previously run, execute this first - sudo pm2 stop signaling-server && sudo pm2 delete signaling-server - # Ensure .env.production is fully configured + # If services were previously running, stop and delete them first + sudo pm2 stop all && sudo pm2 delete all + + # Start all services using the unified configuration file sudo pm2 start ecosystem.config.js ``` -3. **Start the Frontend Service:** - - ```bash - cd frontend - # If previously run, execute this first - sudo pm2 stop privydrop-frontend && sudo pm2 delete privydrop-frontend - - sudo pm2 start npm --name "privydrop-frontend" -- run start - ``` - - The `npm start` command starts the Next.js production server, which listens on port 3000 by default. - -4. **Manage Applications:** +3. **Manage Applications:** - View status: `pm2 list` - - View logs: `pm2 logs ` + - View logs: `pm2 logs ` (e.g., `pm2 logs signaling-server` or `pm2 logs privydrop-frontend`) - Set up startup script: `pm2 startup` followed by `pm2 save` + - Restart services: `pm2 restart all` or specific service `pm2 restart signaling-server` + - Stop services: `pm2 stop all` or specific service `pm2 stop privydrop-frontend` ## 5. Troubleshooting diff --git a/docs/DEPLOYMENT.zh-CN.md b/docs/DEPLOYMENT.zh-CN.md index 6e328fc..99bd66f 100644 --- a/docs/DEPLOYMENT.zh-CN.md +++ b/docs/DEPLOYMENT.zh-CN.md @@ -246,7 +246,7 @@ cd backend && npm run build && cd .. ### 4.6. 使用 PM2 运行应用 -PM2 是一个强大的 Node.js 进程管理器,我们将用它来分别运行后端服务和前端服务。 +PM2 是一个强大的 Node.js 进程管理器,我们将用它来运行后端和前端服务。 1. **全局安装 PM2:** @@ -254,33 +254,24 @@ PM2 是一个强大的 Node.js 进程管理器,我们将用它来分别运行 sudo npm install -g pm2 ``` -2. **启动后端服务:** - 项目后端目录提供了一个 `ecosystem.config.js` 文件用于 PM2。 +2. **使用统一配置文件启动服务:** + + 项目根目录提供了一个统一的 `ecosystem.config.js` 配置文件,可以一次性启动所有服务: ```bash - cd backend - # 如果之前运行过,则先执行 - sudo pm2 stop signaling-server && sudo pm2 delete signaling-server - # 确保 .env.production 已配置完毕 + # 如果之前运行过服务,先停止并删除 + sudo pm2 stop all && sudo pm2 delete all + + # 使用统一配置文件启动所有服务 sudo pm2 start ecosystem.config.js ``` -3. **启动前端服务:** - - ```bash - cd frontend - # 如果之前运行过,则先执行 - sudo pm2 stop privydrop-frontend && sudo pm2 delete privydrop-frontend - - sudo pm2 start npm --name "privydrop-frontend" -- run start - ``` - - `npm start` 会启动 Next.js 的生产服务器,默认监听 3000 端口。 - -4. **管理应用** +3. **管理应用:** - 查看状态: `pm2 list` - - 查看日志: `pm2 logs ` + - 查看日志: `pm2 logs ` (例如:`pm2 logs signaling-server` 或 `pm2 logs privydrop-frontend`) - 设置开机自启: `pm2 startup` 然后 `pm2 save` + - 重启服务: `pm2 restart all` 或指定服务 `pm2 restart signaling-server` + - 停止服务: `pm2 stop all` 或指定服务 `pm2 stop privydrop-frontend` ## 5. 故障排除 diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..5d3feb7 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,34 @@ +module.exports = { + apps: [ + { + name: "signaling-server", + cwd: "./backend", + script: "./dist/server.js", + watch: false, + env: { + NODE_ENV: "production", + BACKEND_PORT: 3001, + }, + log_date_format: "YYYY-MM-DD HH:mm:ss", + error_file: "/var/log/signaling-server-error.log", + out_file: "/var/log/signaling-server-out.log", + max_memory_restart: "500M", + instances: 1, + exec_mode: "fork", + group: "ssl-cert", + }, + { + name: "privydrop-frontend", + cwd: "./frontend", + script: "npm", + args: "run start", + watch: false, + env: { + NODE_ENV: "production" + }, + log_date_format: "YYYY-MM-DD HH:mm:ss", + error_file: "/var/log/privydrop-frontend-error.log", + out_file: "/var/log/privydrop-frontend-out.log", + } + ] +}; \ No newline at end of file