Phusion Passenger and METEOR_SETTINGS

Is anyone using Phusion Passenger 5.0.0 in nginx integration mode and successfully passing METEOR_SETTINGS environment variable?

I’m on ubuntu 14.04 64-bit server. Latest meteor.

I’ve tried /etc/environment without success.

Also tried placing

passenger_env_var METEOR_SETTINGS '{"setting": "value"}';

but did not work. What’s interesting is, if the settings I pass is not valid JSON, meteor barfs out an error. But if it is valid json, it just ignores this.

Does anybody have any pointers for me?

OK, it seems I’m in kind of a dead end here. There is obviously something inherently wrong with meteor’s approach in applying settings to the app and to the meteor tool. The problem may be severe lack of documentation, but also different parties have different opinions.

Phusion Passenger, it seems, has not been able to keep up with the latest changes in meteor’s handling of settings. So I’m not sure if they can/will provide an easy solution to this problem.

Anyway, here are some references if you are reading this in the future and are wondering what I’m talking about.

instead of passenger_env_var use passenger_set_cgi_param

Thanks for the suggestion but passenger_set_cgi_param is not available as a configuration option any more. With version 5.0, it was changed to

https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#PassengerEnvVar

If you include a passenger_set_cgi_param directive, nginx will fail to start.

What does the ngnix error log shows?

Reading again thru the links you provided, are you running it as a bundle? Or just with the production flag (I do remember you wrote it earlier at my gist on GH on similar topic), cause that is disencouraged and as you pointed out with the production flag it just accepts the --settings flag and ignores settings ebb!

Thanks a lot for taking the time to look into this.

I’ve tried both the bundle and the production options. The bundle option works as expected and I’ve already reported it at https://github.com/phusion/passenger/issues/1474#issuecomment-92093959

The problem seems phusion passenger used to support both the bundle and the production flag options and successfully passed in the settings.

But Meteor has changed how settings are applied somewhere around https://github.com/meteor/meteor/commit/24682fd7f44

This nullified passenger’s solution hence our current problem.

At the time I’ve first posted on this thread, I was using a previous version of passenger and was perfectly happy with running meteor --production option, now that I’ve begun upgrading old passenger servers and installing new one, this problem creeped up.

PS: Regarding the discussion around bundles vs flag, my preference is to keep at the flag config strategy as long as the app is in rapid development or hyper care lifecycle. Once the development comes to a full stop (except for maintenance patches), I only then actually bulid up and deploy using that bundle with passenger.

You tried putting passenger_env_var in the sites_enabled/[sitename] file, in a server block?

Yes I did, the configuration already works properly if I deploy as a node build.

If I deploy as a meteor app, the settings get silently swallowed by meteor.

Ah ok, maybe you don’t need it anymore if it’s Passenger + Meteor (not node), but you need to use -settings /path/to/settings.json instead?

That directive expects first param to be METEOR_SETTINGS and second param to be a valid json string, so a path to the settings.json file throws an error.

The problem seems to have followed this timeline:

  1. Meteor used to allow both meteor_settings and --settings during meteor run and meteor_settings for meteor build deployments

  2. passenger supported settings for build deployment, but not for meteor run

  3. passenger added support, passing in meteor_settings to meteor run

  4. meteor changed settings handling and made meteor_settings applied either for meteor tool or node, and --settings flag only applied to meteor run through a json file

  5. passenger did not update its code to reflect that change

So now, what happens is, if you pass in meteor_settings to a meteor run through passenger:

  1. if it is a file path, nginx fails to start

  2. if it is invalid json, nginx starts but meteor fails to start

  3. if it is valid json (the correct settings), it gets ignored by meteor

But if you pass in meteor_settings to a node build through passenger

it works!

My problem is, I was very happy with the previous way it worked, namely to be able to run passenger to manage either meteor run or meteor build and apply my settings either way. That was a very good flexibility providing my efficiency. Now if I use any kind of settings in my app, I either can’t use passenger, or I must meteor build and use that in passenger.

Hi, I tried set nginx with this just like you. But could not read the setting.

passenger_env_var METEOR_SETTINGS '{"private": {"key": "value"}}'

Did log and got error: ReferenceError: METEOR_SETTINGS is not defined

console.log(METEOR_SETTINGS);

Any luck on your side?

When I do

passenger_env_var METEOR_SETTINGS '{"private": {"key": "value"}}'

Your app can see those settings through

console.log(Meteor.settings.private.key) // value

Thanks for reply. I had it working.
I am looking for passing settings via file but not passenger_env_var.
There used to have the option but it gone.

meteor build --settings 

If you know how to ship app with setting file, please let me know.

Many thanks.

@melody

Is meteor build really working? I read the docs, passenger use meteor bundle

I use

meteor build --settings

under development mode. It works.
But for production, I have to set required env variables in the nginx config file. uses the

passenger_env_var

directive.

According to meteor build --help that command option does not have a directive --settings

I am also trying to figure out a way to deploy a meteor app with passenger, and so far I have not been very successful. As a matter of fact, I can’t even get passenger to start with the output of meteor build.

Does anybody have a dead simple recipe that works for nginx + passenger + meteor build (1.2.1)? google finds many answers, but most are outdated or incomplete.

could you post your current conf?

Here is my conf (OSX with homebrew)

    server {
        server_name www.example.com;
        # Turn on Passenger
        passenger_enabled on;
        root /Volumes/Web/Meteor/build/bundle/public;
        passenger_app_type node;
        passenger_startup_file main.js;
        #
        # Tell your app where MongoDB is
        #
        passenger_env_var ROOT_URL http://www.example.com;
        passenger_env_var MONGO_URL mongodb://192.168.1.189:27017/www_example_com;
        passenger_env_var MONGO_OPLOG_URL mongodb://192.168.1.189:27017/local;
}

I did the npm install --production in bundle/programs/server but it throws

bundle/programs/server/node_modules/fibers/future.js:245
						throw(ex);
						      ^
Error: Module did not self-register.

First off, you can provide your app your settings as I described over here

And in your case, it seems like you may be having a problem with your node version.

It should be 0.10.40 and you may be having a newer one getting picked up by passenger, which you can fix with the passenger_nodejs configuration option.