From 9599022c4407b13c8ccfda195b6e396271969d74 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 23 May 2026 14:24:32 +0700 Subject: [PATCH] A --- ecosystem.config.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 ecosystem.config.js diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..54d68f9 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,33 @@ +module.exports = { + apps: [ + { + name: 'nestjs-xnews-service', + script: 'dist/main.js', + // Cấu hình quan trọng + instances: 1, // Chỉ chạy duy nhất 1 bản ghi + exec_mode: 'fork', // Chế độ fork (mặc định cho 1 instance) + cron_restart: '0 */4 * * *', // Restart mỗi giờ một lần + + // Các cấu hình bổ sung nên có + watch: false, // Không watch file ở môi trường prod + autorestart: true, // Tự động restart nếu app bị crash đột ngột + max_memory_restart: '1G', // Restart nếu app ngốn quá 1GB RAM (phòng leak memory) + env: { + NODE_ENV: 'production', + }, + }, + ], + + deploy : { + production : { + user : 'SSH_USERNAME', + host : 'SSH_HOSTMACHINE', + ref : 'origin/master', + repo : 'GIT_REPOSITORY', + path : 'DESTINATION_PATH', + 'pre-deploy-local': '', + 'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production', + 'pre-setup': '' + } + } +};