'use strict'; const { execSync } = require('child_process'); /** * For GET /health `deploy_revision`: honour existing env, else short git SHA when `.git` exists. */ function resolveDeployRevisionForPm2() { const fromEnv = (process.env.DEPLOY_REVISION || process.env.GIT_REVISION || '').trim(); if (fromEnv) { return fromEnv; } try { return execSync('git rev-parse --short HEAD', { cwd: __dirname, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], maxBuffer: 64, }).trim(); } catch (_err) { return ''; } } const _deploy_revision = resolveDeployRevisionForPm2(); /** * PM2 process definition — always runs `listen` (HTTP + RSS cron). * Prefer this over `pm2 start src/index.js ... -- listen` to avoid footguns. * * Usage (inside CT, after clone + npm install + .env): * pm2 start ecosystem.config.cjs * pm2 save && pm2 startup */ module.exports = { apps: [ { name: 'ai-news-writer', script: 'src/index.js', args: ['listen'], cwd: __dirname, instances: 1, autorestart: true, watch: false, max_memory_restart: '512M', // Allow SIGTERM/SIGINT handler to stop cron + close HTTP before PM2 sends SIGKILL kill_timeout: 15_000, time: true, env: { NODE_ENV: 'production', HOST: '0.0.0.0', PORT: '3200', ...(_deploy_revision ? { DEPLOY_REVISION: _deploy_revision } : {}), }, }, ], };