pm2同一套代码启动两个不同的进程

记录一下吧

需求:同一套代码,因为我需要启动两个进程,而且进程之间的环境变量不同

最开始,我直接在process.json文件的apps里面只有一个元素,是.ts文件,也就是typescript写的源码,所以最初我想的简单,直接在apps属性里面再加一个app就行了,但是尝试了两次,都会直接把内存吃光,后来我想是不是我编译成js就行了,后来试了,果然可以了

 

{
  "apps" : [{
    "name"        : "monitor-bot-1",
    "script"      : "./dist/index.js",
    "exec_mode"   : "fork",
    "instances"   : 1,
    "error_file"  : "../logs/monitor/monitor.err.log",
    "out_file"    : "../logs/monitor/monitor.log",
    "max_memory_restart" : "350M",
    "env": {
      "ID": "mybotid1",
      "WECHATY_PUPPET_PADPLUS_TOKEN": "mytoken1",
      "BOT_IP": "127.0.0.1",
      "PLATFORM": "linux",
      "WECHATY_LOG": "info"
    }
  }, {
    "name"        : "monitor-bot-2",
    "script"      : "./dist/index.js",
    "exec_mode"   : "fork",
    "instances"   : 1,
    "error_file"  : "../logs/monitor/monitor.err1.log",
    "out_file"    : "../logs/monitor/monitor1.log",
    "max_memory_restart" : "350M",
    "env": {
      "ID": "mybotid2",
      "WECHATY_PUPPET_PADPLUS_TOKEN": "mytoken2",
      "BOT_IP": "127.0.0.1",
      "PLATFORM": "linux",
      "WECHATY_LOG": "info"
    }
  }]
}

 

但目前不知道当初为啥直接运行ts的时候可以直接运行,因为网上说了,pm2是不能直接运行typescript的

 

pm2版本4.1.2

 

posted @ 2020-07-12 19:46  顾晓北  阅读(1075)  评论(0编辑  收藏  举报