const path = require('path');

module.exports = {
  apps: [
   {
      name: 'yfios-mqtt-auth',
      cwd: './packages/yfios-mqtt-auth/',
      script: './dist/main.js',    
      instances: "max",                 // 根据 CPU 核心数启动最大副本数
      exec_mode: "cluster",           // 开启集群模式

      restart_delay: 3000,              // 重启延迟     
      kill_timeout: 3000,                // 优雅退出时间
      exp_backoff_restart_delay: 100,
      autorestart: true                  // 程序崩溃后自动重启
    },
    {
      name: 'yfios-mqtt-collector',
      cwd: './packages/yfios-mqtt-collector/',
      script: './dist/main.js',    
      instances: 'max',                 // 开启集群模式，实现 MQTT 5.0 共享订阅负载均衡
      exec_mode: 'cluster',

      restart_delay: 3000,             // 重启延迟     
      kill_timeout: 3000,               // 优雅退出时间
      exp_backoff_restart_delay: 100,
      autorestart: true                  // 程序崩溃后自动重启
    },
    {
      name: 'yfios-service',
      cwd: './packages/yfios-service/',
      script: './dist/main.js',   
       instances: 1,
      exec_mode: 'fork',

      restart_delay: 3000,              // 重启延迟     
      kill_timeout: 3000,                // 优雅退出时间
      exp_backoff_restart_delay: 100,
      autorestart: true                   // 程序崩溃后自动重启
    },
    {
      name: 'yfios-data-save',
      cwd: './packages/yfios-data-save-service/',
      script: './dist/main.js',   
      instances: 1,
      exec_mode: 'fork',

      restart_delay: 3000,             // 重启延迟     
      kill_timeout: 3000,               // 优雅退出时间
      exp_backoff_restart_delay: 100,
      autorestart: true                 // 程序崩溃后自动重启
    }
  ]
};