Hotpush code not working on passenger production application


#1

Hello evryone, I’m having a problem with meteor + passenger.

actually I’m trying to build the application but the hotpush code does not work at all, but it does when I test it locally.

#locally
as far as I know locally I do this:

meteor build /Users/Prince/Projects/BUILD/ --server http://192.168.137.158:4321

then I sign the application etc etc etc and I get my APK on ‘…/BUILD/android/my.apk’ right?

meteor run --settings settings/settings-local.json --mobile-server http://192.168.137.158:4321

192.168.137.158 is my LAN IP, and my phone is connected to that LAN and the port 4321 is a random port that I use (to see if the problem was the port 3000).

so as you can see I’m using a settings file and this is the content of that file:

{
  "private": {
    "type": "development",
    "url": "http://192.168.137.158:4321",
    "port": 433,
    "webServiceUrl": "http://10.10.10.242:8080/ayamobi/services/rest/1.0/",
  }
}

and then on the start up I do this:

Meteor.startup(function () {
    var theURL = Meteor.settings.private.url;
    Meteor.absoluteUrl.defaultOptions.rootUrl = theURL;
    process.env.ROOT_URL = theURL;
    process.env.MOBILE_ROOT_URL = theURL;
    process.env.MOBILE_DDP_URL = theURL;
    process.env.PORT = Meteor.settings.private.port;
    process.env.DDP_DEFAULT_CONNECTION_URL = theURL;
    console.log(process.env);

});

with this, my hotpush code works on my LAN network, I install the application and then I do changes on the code and my application flashes and it has the changes as I want, perfect right?

#production
the problem comes when I want to deploy the application on my server which is using passenger and I run the build throught jenkins, so in order to do it we have this:

ssh root@$2 "cd /var/www/meteor/ayamobi/bundle/programs/server && npm install --production && npm install --save simple-oauth2"
ssh root@$2 "passenger-config restart-app /var/www/meteor/ayamobi/bundle "

then we have

export ANDROID_HOME="/var/sdk/android-sdk-linux"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export ROOT_URL="$protocol://$server"
export DDP_DEFAULT_CONNECTION_URL="$protocol://$server:$port"
export PORT="$port"
export MOBILE_ROOT_URL="$protocol://$server:$port"
export MOBILE_DDP_URL="$protocol://$server:$port"
METEOR_SETTINGS="passenger_env_var METEOR_SETTINGS '"cat /var/mobile/$buildenv/src/settings/$settings“’;”’

and then I build the APK
usr/local/bin/meteor npm install --save simple-oauth2
/usr/local/bin/meteor build --directory /var/mobile/build/$buildenv/ --server="$protocol://$server:$port" --mobile-settings settings/$settings

where:
$protocol = https
$server = my.domain.com (this is for example)
$port = 443

and the settings passed to that file are:

{
  "private": {
    "type": "development",
    "url": "https://my.domain.com:443,
    "port": 433,
    "webServiceUrl": "http://10.10.10.242:8080/ayamobi/services/rest/1.0/",
  }
}

this should do the trick right? now, going deeper I found the index.html of the BUILD and check what I have on my meteor.runtime

DDP_DEFAULT_CONNECTION_URL:"https://my.domain.com:443/"
ROOT_URL:"https://my.domain.com:443/"
ROOT_URL_PATH_PREFIX:""
appId:"1jt099an8obv216wcrhd"
autoupdateVersionCordova:"43928ee2d7a20a75c3254f963ce4fdf992139dd7"
NODE_ENV:"production"
TEST_METADATA:"{}"
meteorRelease:"METEOR@1.3.3.1"

now, what is happening here? when I first install the application it works, I show the Meteor.connection.status() on the mobile and the web view and they are connected BUT when I do the build again (even without changes or with changes) the web app still works and takes the changes if they were made and the mobile app stops working, it doesnt connect to the server, it says in the status connection : WAITING connected: false.

could it be the way that we are deploying the app? this is so weird… anybody has an idea?

Thanks! :slight_smile:


#2

Why did you feel the need to do all that config settings stuff? Doesn’t it work when you just run it on a device with this:

And when your deploy for production it just build and use the --server option? https://guide.meteor.com/mobile.html#building-for-production


#3

Hello, thanks for the fast response :slight_smile:

actually that is what I’m doing locally and in production, as you can see this is what I use to build in production:

/usr/local/bin/meteor build --directory /var/mobile/build/$buildenv/ --server="$protocol://$server:$port" --mobile-settings settings/$settings

and as I said:
$protocol = https
$server = my.domain.com (this is for example)
$port = 443

so you can see that I’m using --server https://my.domain.com:443
but this doesn’t work.

Regarding my settings file has another settings like OAuth or urls for webservices.

the problem is that when I build for the first time and I get the first APK, it works… but then If I rebuild the server with new changes it doesnt, actually my app wont connect to the server anymore.


#4

Did you also configure your server with the correct ROOT_URL environment variable? See the guide for more information on why this is needed.


#5

Hello,

Answering to your question, yes, I do, actually I took those variables from my settings file as you can see also on the meteor startup function I do this:

Meteor.startup(function () {
   var theURL = Meteor.settings.private.url;
   Meteor.absoluteUrl.defaultOptions.rootUrl = theURL;
   process.env.ROOT_URL = theURL;
   process.env.MOBILE_ROOT_URL = theURL;
   process.env.MOBILE_DDP_URL = theURL;
   process.env.PORT = Meteor.settings.private.port;
   process.env.DDP_DEFAULT_CONNECTION_URL = theURL;
   console.log(process.env);

});

to set all the URLS that I need.

could it be something with the port?


#6

Did you try setting them really as environment variable? Because onStartup is the final moment of the whole process of starting. Like: When everything is ready now run this code please. Not sure if the internals will follow your url setting because then they are all ready.


#7

ummmm, I see, and then, how can i tell if the variables are really set? is there a way to do it?


#8

You can still do your console.log(process.env);.


#9

I do it, and actually I have a Meteor.call in order to see in the client what is set and I found that everything is correct :frowning:

{
    APP_ID: "1jt099an8obv216wcrhd",
    DDP_DEFAULT_CONNECTION_URL: "https//my.domain:443",
    DISABLE_WEBSOCKETS: "1",
    HOME: "/",
    IN_PASSENGER: "1",
    LOGNAME: "nobody",
    METEOR_SETTINGS:'{ "private" { "type" "development", "url" "https//my.domain.com:443", "webServiceUrl"     "http//10.10.10.2428080/ayamobi/services/rest/1.0/", "port" "443", "mobile-server" "https//my.domain:443", "server" "https//my.domain:443", "credentials" { "clientID" "xxxxxx", "clientSecret" "xxxxxxx", "site" "http//xxxxxx:8080/", "authorizationPath" "/oauth/authorize", "tokenPath" "/oauth/token" } }, "public" { "expireLoginTime" 10 } }'
    MOBILE_DDP_URL: "https//my.domain:443",
    MOBILE_ROOT_URL: "https//my.domain:443",
    MONGO_URL: "mongodb//10ef40e90e@10.10.10.3127017/",
    NODE_ENV: "production",
    NODE_PATH: "/usr/share/passenger/node",
    PASSENGER_APP_ENV: "production",
    PASSENGER_DEBUG_DIR: "/tmp/passenger.spawn-debug.XXXXP58WV1",
    PASSENGER_USE_FEEDBACK_FD: "true",
    PORT: "443",
    PWD: "/var/www/meteor/ayamobi/bundle",
    PYTHONUNBUFFERED: "1",
    RACK_ENV: "production",
    RAILS_ENV: "production",
    ROOT_URL: "https//my.domain:443",
    SERVER_SOFTWARE: "nginx/1.10.0 Phusion_Passenger/5.0.28",
    SHELL: "/sbin/nologin:",
    TEST_METADATA: "{}",
    USER: "nobody",
    WSGI_ENV: "production",

}


#10

As @lucfranken says, you must set these as proper environment variables. By the time Meteor.startup is run everything’s already set up.


#11

so, I should remove everything from the meteor.statup right? and then see what I get.

how can I check from the apk where is it going to connect? it is right to check on the meteor.runtime on the index.html file?


#12

Yes and set it in your platform. What OS do you use?


#13

to develop I’m using OSX, but the production server is runing nginx with phusion passenger.


#14

Have no experience with it but something like this should work:

https://www.phusionpassenger.com/library/indepth/environment_variables.html


#15

Hello, Yes, as I mentioned we use them to build as you can see in my first post:

export ANDROID_HOME="/var/sdk/android-sdk-linux"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export ROOT_URL="$protocol://$server"
export DDP_DEFAULT_CONNECTION_URL="$protocol://$server:$port"
export PORT="$port"
export MOBILE_ROOT_URL="$protocol://$server:$port"
export MOBILE_DDP_URL="$protocol://$server:$port"
METEOR_SETTINGS="passenger_env_var METEOR_SETTINGS '"cat/var/mobile/$buildenv/src/settings/$settings"';"'

now, updating what I ahve tried, I removed the variables at the Meteor.startup function so nothing is in that function and here are my results:

this is my console.log(process.env)

{
  "PASSENGER_USE_FEEDBACK_FD": "true",
  "SERVER_SOFTWARE": "nginx/1.10.0 Phusion_Passenger/5.0.28",
  "PASSENGER_DEBUG_DIR": "/tmp/passenger.spawn-debug.XXXXfswlF4",
  "USER": "nobody",
  "LOGNAME": "nobody",
  "SHELL": "/sbin/nologin",
  "HOME": "/",
  "PWD": "/var/www/meteor/ayamobi/bundle",
  "IN_PASSENGER": "1",
  "PYTHONUNBUFFERED": "1",
  "NODE_PATH": "/usr/share/passenger/node",
  "RAILS_ENV": "production",
  "RACK_ENV": "production",
  "WSGI_ENV": "production",
  "NODE_ENV": "production",
  "PASSENGER_APP_ENV": "production",
  "MONGO_URL": "mongodb://dev-ayamobi:10ef40e90e@10.10.10.31:27017/devayamobile",
  "ROOT_URL": "https://my.domain.com:443",
  "DDP_DEFAULT_CONNECTION_URL": "https://my.domain.com:443",
  "PORT": "443",
  "MOBILE_ROOT_URL": "https://my.domain.com:443",
  "MOBILE_DDP_URL": "https://my.domain.com:443",
  "DISABLE_WEBSOCKETS": "1",
  "APP_ID": "koplmsv0uvws1ionnv3",
  "TEST_METADATA": "{}"
}

and this is what I get from the meteor_runtime_config

{
  "meteorRelease": "METEOR@1.3.3.1",
  "ROOT_URL": "https://my.domain.com:443/",
  "ROOT_URL_PATH_PREFIX": "",
  "DDP_DEFAULT_CONNECTION_URL": "https://my.domain.com:443/",
  "autoupdateVersionCordova": "e410ce362a366bd02d268fd4cc13bbd888aeb00e",
  "appId": "koplmsv0uvws1ionnv3",
  "meteorEnv": {
    "NODE_ENV": "production",
    "TEST_METADATA": "{}"
  }
}

I don’t see anything wrong with this. do you? is there something else that I need to check to see if the hotpushcode works?
it looks like the enviroment variables are right and the server is started with those variables… I want to launch my app to prod :frowning:


#16

Hello, following with this problem? anyone has a solution?

do you know if this has something about with the installation of node

"cd /var/www/meteor/ayamobi/bundle/programs/server && npm install --production && npm install --save simple-oauth2"

everytime that I do a build?