How can I get my app to run a compiled Go binary on my server?


#1

Edit: Is this even possible? I have compiled Go code called ncbi-output that I want to run on the server in response to an event on the client side. I have learned that the API for accessing static assets deal with them as read only.

This is what i have in my server/main.js

import { Meteor } from 'meteor/meteor';

Meteor.startup(function () {

  var Future = Npm.require("fibers/future");

  var exec = Npm.require("child_process").exec;

  Meteor.methods({

    SequenceDownloader: function (retmax, term, taxon) {

      this.unblock();

      var future=new Future();

      if( retmax == ' -retmax ' ) { // If -retmax is not set, set to default retmax=1
        retmax=" -retmax 1"
      }

      if( term == ' -term ' ) { // If term flag is not set don't include the -term flag in the call
        term=""
      }

      if( taxon == ' -taxon ') { // If taxon flag is not set don't include the -taxon flag in the call
        taxon=""
      }

      var command='./assets/app/ncbi-output' + retmax + taxon + term; // Example term flag: -term title,mitochondrion,AND

      exec(command, function(error,stdout,stderr){

        if(error){

          console.log(error);

          throw new Meteor.Error(500,command+" failed");

        }

        future.return(stdout.toString());

      });

      return future.wait();

    }

  });
});

But I get this returned

/bin/sh: ./assets/app/ncbi-output: Permission denied


#3

Ok so I was able to get it to run locally by adding

exec('chmod +x ./assets/app/ncbi-output');

but when I deploy the app using meteor-up, the app page looks fine but when the event is fired that is supposed to run the Go binary nothing happens and in the console I see

Failed to load resource: the server responded with a status of 502 ()`
GET https://virtualapprentice.us/sockjs/info?cb=jftapnyqf4 502 ()      fbf9e767f3cf4e0c5a42d75dc16ac03f24a8a5f6.js?meteor_js_resource=true:55 

How can I debug this? I am very new to web development and would really appreciate it if someone could point me in the right direction!


#4

Ok I got it to work, here’s what I did.

  • In server/main.js I set the command to …/ncbi-output
  • I deployed the app using mup
  • I put the executable binary in /opt/app/current/bundle/programs/ncbi-output

#5

Well, that got it to work sometimes. I’m still getting a 502 error most of the time…

I wonder if this is something that’s just not done? I haven’t found any discussion about running external binaries from a meteor app.