设置 pm2 以监控流星应用程序的步骤

Steps to setup pm2 to monitor a meteor app

我正在尝试使用 pm2 来监控我的 meteor 应用程序,打算解决 cpu 100% 使用率的问题。

我参考了PM2 + Meteor Environment Setup,但结果看起来失败了。

我的想法是根本没有启动流星进程。欢迎任何想法。

顺便说一句,我已经尝试过pm2-meteor,但可能因为它没有维护,现在无法运行成功。

我的代码结构是这样列出的,

+- cloud
  +- package.json
  +- client
  +- server
  +- pm2.json
  +- private
  +- public
  +- server

在正常模式下,我 运行 网络应用程序通过获取云文件夹和“流星”指令。

我发现问题的原因在于

所以在更新我机器上的nodejs之后,我需要决定选择一种方式来运行 pm2

1. pm2-meteor in https://github.com/andruschka/pm2-meteor
2. run mongodb and it listens to 172.0.0.1:27010 
   + meteor build the app to be .tar.gz
   + pm2 run meteor app

我用的是2.所以步骤是,

1. install mongodb, pm2, nodejs(nodejs installation with nvm please)

2. In order to create a mongodb service
   - launch mongod by 
     mongod -dbpath=$(some_accessible_path) -logpath=$(some_accessible_path) --fork --replSet meteor

3. run mongo and get to mongo shell and key in commands bellow
   a. var config = {_id:"meteor",members:[{_id:0,host:"127.0.0.1:27017"}]}
   b. rs.initiate(config)
   if the return value is {"ok":1}, mongodb service is ready.

4. pack meteor app
   a. mkdir ~/cloud_build
   b. get to the source code folder and use the command
      meteor build --architecture=os.linux.x86_64 ~/cloud_build
   c. cd ~/cloud_build
   d. tar xvf some.tar.gz
   e. you will get a bundle folder
   f. cd that_bundle_folder/program/server && npm install

5. run pm2
   a. create a file of pm2.json in the bundle folder 
   b. pm2 start pm2.json

pm2.json 看起来像下面的东西

{
  "apps": [{
  "name": "appName",
  "cwd": "/yourhome/cloud_build/bundle",
  "script": "main.js",
  "env": {
  "NODE_ENV": "production",
  "WORKER_ID": "0",
  "PORT": "3000",
  "ROOT_URL": "http://yourweburl",
  "MONGO_URL": "mongodb://localhost:27017/meteor",
  "MONGO_OPLOG_URL": "mongodb://localhost:27017/local",
  "HTTP_FORWARDED_COUNT": "1",
  "METEOR_SETTINGS": {}
  }
  }]
}

然后webapp可以在http://yourweburl:3000

访问