ecosystem.config.cjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // PM2 process config
  2. // Start: pm2 start ecosystem.config.cjs
  3. // Save: pm2 save
  4. // Startup: pm2 startup systemd
  5. const fs = require("fs");
  6. const path = require("path");
  7. // Parse .env.production manually so PM2 always picks up the latest values
  8. // regardless of PM2 version's env_file support.
  9. function loadEnv(envPath) {
  10. try {
  11. const content = fs.readFileSync(envPath, "utf8");
  12. const env = {};
  13. for (const line of content.split("\n")) {
  14. const trimmed = line.trim();
  15. if (!trimmed || trimmed.startsWith("#")) continue;
  16. const eqIdx = trimmed.indexOf("=");
  17. if (eqIdx === -1) continue;
  18. const key = trimmed.slice(0, eqIdx).trim();
  19. const val = trimmed.slice(eqIdx + 1).trim();
  20. env[key] = val;
  21. }
  22. return env;
  23. } catch {
  24. return {};
  25. }
  26. }
  27. const ENV_FILE = path.resolve(__dirname, ".env.production");
  28. const env = loadEnv(ENV_FILE);
  29. module.exports = {
  30. apps: [
  31. {
  32. name: "homelegance-chat",
  33. script: "./dist/index.js",
  34. cwd: "/redant/web/homelegance-chatbot",
  35. env, // inject all vars from .env.production
  36. instances: 1,
  37. autorestart: true,
  38. max_memory_restart: "512M",
  39. error_file: "/var/log/pm2/homelegance-chat-error.log",
  40. out_file: "/var/log/pm2/homelegance-chat-out.log",
  41. log_date_format: "YYYY-MM-DD HH:mm:ss",
  42. },
  43. ],
  44. };