Q42 / meteor-gce

Install scripts to run Meteor on Google Compute Engine
MIT License
55 stars 13 forks source link

Error: MONGO_URL must be set in environment #14

Open valorloff opened 8 years ago

valorloff commented 8 years ago

meteor app and mongodb on different GCE VMs in same project:

startup.sh: ................ export MONGO_URL='mongodb://root:****@10.110.0.2:27017' (CHECKED: from mongo-client connecting OK) .......................................

pm2 start main.js --name 'my-app' --watched
[PM2] Starting /opt/bundle/main.js in fork_mode (1 instance)
[PM2] Done.
┌────────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬──────────┐
│ App name   │ id │ mode │ pid  │ status │ restart │ uptime │ cpu │ mem       │ watching │
├────────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼──────────┤
│ my_app │ 0  │ fork │ 8676 │ online │ 0       │ 0s     │ 4%  │ 20.1 MB   │ disabled │
└────────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴──────────┘

.pm2/logs/my_app-error-0.log:

Error: MONGO_URL must be set in environment
    at Object.<anonymous> (packages/mongo/remote_collection_driver.js:36:11)
    at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
    at new Mongo.Collection (packages/mongo/collection.js:103:40)
    at AccountsServer.AccountsCommon (packages/accounts-base/accounts_common.js:23:18)
    at new AccountsServer (packages/accounts-base/accounts_server.js:18:5)
    at meteorInstall.node_modules.meteor.accounts-base.server_main.js (packages/accounts-base/server_main.js:9:12)
    at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
    at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
    at /opt/bundle/programs/server/packages/accounts-base.js:1838:15
    at /opt/bundle/programs/server/packages/accounts-base.js:1849:3
chees commented 8 years ago

Did you also change your MONGO_URL here? https://github.com/Q42/meteor-gce/blob/master/startup.sh#L71

Did you upload your changed startup.sh to your bucket?

To debug you could add an echo $MONGO_URL somewhere in your script to see if it picks up the right environment variable.

valorloff commented 8 years ago

Thanks for the quick response) of course! export MONGO_URL='mongodb://' in place, startup.sh is fresh and in gs://bucket. But where i can insert debug row echo $MONGO_URL, if 'export' rows is last in startup.sh?

chees commented 8 years ago

Hmm, it looks like more people have problems with pm2 not picking up environment variables in some cases: https://github.com/Unitech/pm2/issues/83

Some people mention that setting the environment variables in a process.json and starting pm2 with that works:

http://pm2.keymetrics.io/docs/usage/application-declaration/

Could you try that?

valorloff commented 8 years ago

I try MONGO_URL='mongodb://root:*****@10.240.0.3:27017' ROOT_URL='http://localhost' pm2 start main.js --name 'my-app' ---------.pm2/logs/dst-orders-error-0.log-----........................................

Note: you are using a pure-JavaScript implementation of bcrypt.
While this implementation will work correctly, it is known to be
approximately three times slower than the native implementation.
In order to use the native implementation instead, run
  meteor npm install --save bcrypt
in the root directory of your application

.................................................................................... so, need change startup.sh cd bundle (cd programs/server && npm install) to: cd bundle (cd programs/server && meteor npm install --save bcrypt) ?

valorloff commented 8 years ago

something I have no luck with your script ) fresh experiment: prepare process.json with:

env: {
      "HOME":"/home/",
      "MONGO_URL":"mongodb://root:***@10.240.0.3:27017",
      "ROOT_URL":"http://localhost",
      "MAIL_URL":"smtp://*****:*****@smtp.googlemail.com:465",
      "PORT":"3000"
    }

pm2 start process.json:

 Error: Cannot find module 'fibers'
     at Function.Module._resolveFilename (module.js:325:15)
     at Function.Module._load (module.js:276:25)
     at Function._load (/usr/lib/node_modules/pm2/node_modules/pmx/lib/transaction.js:62:21)
     at Module.require (module.js:353:17)
     at require (internal/module.js:12:17)
     at Object.<anonymous> (/opt/bundle/programs/server/boot.js:1:75)
     at Module._compile (module.js:409:26)
     at Object.Module._extensions..js (module.js:416:10)
     at Module.load (module.js:343:32)
     at Function.Module._load (module.js:300:12)
chees commented 8 years ago

The bcrypt warning is probably unrelated to this problem. I think you're on the right track with the process.json. Usually when it can't find fibers something went wrong with npm install. Check if that ran correctly and if the node_modules is in the right location.

valorloff commented 8 years ago

Local app on local machine work ok,... may be, incorrectly meteor build process? how check it? may be, try build options? please advise me)

chees commented 8 years ago

Hmm, I just noticed this script still installs Node 0.10: https://github.com/Q42/meteor-gce/blob/master/startup.sh#L17

Meteor now uses Node 4 as far as I know, so try replacing line 17 in the script with this:

curl -sL https://deb.nodesource.com/setup_4.x | bash -

valorloff commented 8 years ago

I have done it from the very beginning: my install row is:

curl --fail -ssL -o setup-nodejs https://deb.nodesource.com/setup_4.x &&
  bash setup-nodejs &&
  apt-get install -y nodejs build-essential nodejs nginx

but i I have heard, that meteor 1.4 need node 4.4.7 apparently, not the case

valorloff commented 8 years ago

made by hand:

curl -sL https://deb.nodesource.com/setup_4.x | bash -
apt-get install nodejs
pm2 kill
pm2 start process.json

Didn't work ( Error: Cannot find module 'fibers' how to defeat this "fibers" ?

valorloff commented 8 years ago

after added to startup.sh row npm install fibers source-map-support underscore semver now app launched with hand typing pm2 start .. only, not automatically )

chees commented 7 years ago

Glad you (almost) got it working. I haven't used this script anymore in a long time, so for maybe a better up to date version you could also try Meteor Up: https://github.com/kadirahq/meteor-up

valorloff commented 7 years ago

I liked your docker free method, it more improvable)