PM2 + Meteor not working

2019-07-04 03:46发布

问题:

I get an error when trying to run it:

~/projects/test-app 
/usr/local/bin/meteor:3
# This is the script that we install somewhere in your $PATH (as "meteor")

Here is the command I run:

pm2 start meteor-pm2.json

And here is meteor-pm2.json:

{
  "name" : "test-app",
  "script" : "/usr/local/bin/meteor",
  "MAIL_URL":"smtp://yourmail_configuration_here",
  "MONGO_URL":"mongodb://localhost:27017/meteor",
  "ROOT_URL":"https://www.mysite.com/",
  "PORT":"3000",
  "out_file":"/home/josh/logs/app.log",
  "error_file":"/home/josh/logs/err.log"
}

I also try this: cat start

#!/bin/bash

MONGO_URL="mongodb://localhost:27017/meteor"
PORT=3000
ROOT_URL="https://www.mysite.com/"

/usr/local/bin/meteor

and I run it with:

pm2 start ./start -x interpreter bash

and I get:

/usr/local/bin/meteor
^
ReferenceError: usr is not defined

when i modify the bash script by adding the export:

#!/bin/bash

export MONGO_URL="mongodb://localhost:27017/meteor"
export PORT=3000
export ROOT_URL="https://www.mysite.com/"

/usr/local/bin/meteor

I get:

export - SyntaxError: Unexpected reserved word

Any ideas what am I doing wrong? Is pm2 trying to run the bash script in it's own special script interpreter that doesn't allow the use of export?

回答1:

I believe this process.json syntax is more correct:

{
  "apps": [
    {
      "name": "myAppName",
      "script": "./bundle/main.js",
      "log_date_format": "YYYY-MM-DD",
      "exec_mode": "fork_mode",
      "env": {
        "PORT": 3000,
        "MONGO_URL": "mongodb://127.0.0.1/meteor",
        "ROOT_URL": "https://myapp.example.com/",
        "BIND_IP": "127.0.0.1"
      }
    }
  ]
}

then I just start it using run.sh which contains:

#!/bin/sh

#
# This shell script starts the actual
# app in the production environtment.
#

pm2 start process.json -i max # Enable load-balancer and cluster features

Note: the BIND_IP env var is there to change it from the default (0.0.0.0). The 0.0.0.0 would make the app accessible around the ssl proxy layer (if you use SSL/TLS with nginx or some other web server and the BIND_IP is set to 0.0.0.0 then pretty much anyone could access it via http://myapp.example.com:3000 around the encrypted layer, unless you block that port in your web server's configuration).



回答2:

This is how I got my meteor app (Telescope) working

 ROOT_URL=http://localhost:3000 PORT=3000 MONGO_URL=mongodb://127.0.0.1:27017/Telescope pm2 start main.js

inside .meteor/local/build



回答3:

Meteor isn't actually running from /usr/local/bin/meteor, that script is only used for bootstrapping etc, that when done redirects to ~/.meteor/meteor

From /usr/local/bin/meteor:

# All this script does is exec ~/.meteor/meteor. But what if you don't have it
# yet? In that case, it downloads a "bootstrap tarball", which contains the
# latest version of the Meteor tools, and plops it down at ~/.meteor. In fact,
# once you've run this once, you don't even really need this script: you can put
# ~/.meteor/ into your PATH, or a symlink to ~/.meteor/meteor into some other
# PATH directory. No special permissions needed!

So what you need to do is change your script pointer to use meteor in your "Warehouse dir" (~/meteor/meteor)



回答4:

This means that pm2 expects some syntax and finds another in the start script. In order to direct it to the right syntax, add this to your config.json file:

"interpreter"  : "bash"

P.S.: addition of this parameter to the command line didn't work



标签: meteor pm2