GithubHelp home page GithubHelp logo

strongloop / node-foreman Goto Github PK

View Code? Open in Web Editor NEW
1.3K 36.0 132.0 1.04 MB

A Node.js Version of Foreman

Home Page: http://strongloop.github.io/node-foreman/

License: Other

JavaScript 88.70% Shell 11.30%

node-foreman's Introduction

Node Foreman Build Status

Node Foreman is a Node.js version of the popular Foreman tool, with a few Node specific changes.

Foreman is a manager for Procfile-based applications. Its aim is to abstract away the details of the Procfile format, and allow you to either run your application directly or export it to some other process management format.

Install

Install the command line tool

npm install -g foreman

Get usage

nf --help

Deviations from the original Foreman

  • Each worker has an additional automatic environment variable, FOREMAN_WORKER_NAME, that contains the process name and worker number.
    • example: web.1, worker.1

How to Contribute

I encourage anyone and everyone to help. If you have a specific change in mind, open an issue; we can talk about it there.

If you would like to make a code change, go ahead. Fork the repository, open a pull request. Do this early, and talk about the change you want to make. Maybe we can work together on it.

Refactor Refactor Refactor! You are free to add features, or just help clean things up.

Usage

Node Foreman can be run with as little as nf start, as long as npm start has been defined. For more complicated applications you will want to define a Procfile for your various server processes and an .env file to pre-load environmental variables.

Your module directory should end up looking like the following:

List Foreman Directory

Once your Procfile is defined, run your application with nf start:

Start Foreman

Node Foreman always starts in the foreground and expects your applications to do the same. If your processes exit, Node Foreman will assume an error has occurred and shut your application down.

Instead of daemonizing, you should use nf export to ready your application for production.

For more information try any of the following:

$ nf --help
$ nf start --help
$ nf run --help
$ nf export --help

Procfile

The Procfile format is a simple key : command format:

web: node web_server.js
api: node api_server.js
log: node log_server.js

Each line should contain a separate process.

Environmental Variables

Create a .env file to pre-load environmental variables with the format:

MYSQL_NAME=superman
MYSQL_PASS=cryptonite

The equivalent .env file may alternatively be a valid JSON document:

{
    "mysql":{
        "name": "superman",
        "pass": "cryptonite"
    }
}

The above JSON document will be flattened into env variables by concatenating the nested values with an underscore. Environmental variables are passed in fully capitalized.

{
    "mysql":{
        "name": "superman",     # => MYSQL_NAME=superman
        "pass": "cryptonite"    # => MYSQL_PASS=cryptonite
    }
}

There is no need to specify which type of file you wish to use.

The PATH environment variable

The PATH variable is given special treatment and is always read from the environment that the nf command has been executed from, rather than your .env file. To set a different PATH execute nf with the PATH variable set appropriately.

PATH=/opt/foo:/opt/bar:$PATH nf export

Best Practices

Generally you should not check your .env file into version control. The .env file contain only parameters that depend on where the application gets deployed. It should not contain anything related to how the application is deployed.

For example, good candidates for the .env file are MySQL connection information, port bindings, and other passwords.

The Run Command

Tasks or commands that require the environment variables from the .env file can be initiated by using nf run <command>.

Advanced Usage

Node Foreman lets you start multiple jobs of the same type:

$ nf start web=5

18:51:12: web.1     |  Web Server started listening on 0.0.0.0:5000
18:51:12: web.2     |  Web Server started listening on 0.0.0.0:5001
18:51:12: web.3     |  Web Server started listening on 0.0.0.0:5002
18:51:12: web.4     |  Web Server started listening on 0.0.0.0:5003
18:51:12: web.5     |  Web Server started listening on 0.0.0.0:5004

Each job will be started as its own process, receiving a different PORT environmental variable. The port number for processes of the same type will be offset by 1. The port number for processes of different types will be offset by 100.

$ nf start web=2,api=2

18:51:12: web.1     |  Web Server started listening on 0.0.0.0:5000
18:51:12: web.2     |  Web Server started listening on 0.0.0.0:5001
18:51:12: api.1     |  Api Server started listening on 0.0.0.0:5100
18:51:12: api.2     |  Api Server started listening on 0.0.0.0:5101

Export to Production

Node Foreman is designed to be in a development environment, however it can export an Upstart job for use in production. The Upstart file has no dependency on Node Foreman.

$ nf export
Loaded ENV .env File as JSON Format
Wrote  :  ./foreman-web-1.conf
Wrote  :  ./foreman-web.conf
Wrote  :  ./foreman-api-1.conf
Wrote  :  ./foreman-api.conf
Wrote  :  ./foreman-log-1.conf
Wrote  :  ./foreman-log.conf
Wrote  :  ./foreman.conf

You can inspect your upstart files before placing them in the right directory, or have foreman do it for you:

$ sudo nf export -o /etc/init
Loaded ENV .env File as JSON Format
Wrote  :  /etc/init/foreman-api-1.conf
Wrote  :  /etc/init/foreman-web.conf
Wrote  :  /etc/init/foreman-api.conf
Wrote  :  /etc/init/foreman-log.conf
Wrote  :  /etc/init/foreman-log-1.conf
Wrote  :  /etc/init/foreman-web-1.conf
Wrote  :  /etc/init/foreman.conf

Start and stop your jobs with

$ sudo start foreman
Starting foreman... ok
$ sudo stop foreman

The export will occur with whatever environmental variables are listed in the .env file.

systemd Support

This section is beta

Optionally specify a type -t systemd during export for systemd support.

Supervisord Support

You can also use a type -t supervisord during export for supervisord support.

This will generate a APP.conf file grouping the application processes and a APP-PROCESS-N.conf file for each process.

$ nf export --type supervisord
Loaded ENV .env File as JSON Format
Wrote  :  ./foreman-web-1.conf
Wrote  :  ./foreman-api-1.conf
Wrote  :  ./foreman-log-1.conf
Wrote  :  ./foreman.conf

You can start / stop / restart individual processes.

$ sudo supervisorctl start 'foreman:foreman-web-1'
$ sudo supervisorctl stop 'foreman:foreman-web-1'
$ sudo supervisorctl restart 'foreman:foreman-web-1'

Or the entire group of processes

$ sudo supervisorctl start 'foreman:*'
$ sudo supervisorctl stop 'foreman:*'
$ sudo supervisorctl restart 'foreman:*'

Advanced Exports

You can specify the type and number of processes exported using the type=num syntax:

$ nf export web=2,api=2

Use -u <USER> to have the exported job run as USER. Note that if you need to bind to privileged ports, you must start as root. In such a case, we advise you to drop user permissions after binding.

If you want to call your upstart job something other than foreman, use -a <JOBNAME> and manage your jobs with sudo start <JOBNAME>.

Reverse Proxy

Node.js processes are supposed to be stateless. Applications scale by starting multiple processes that either share a socket, or sit behind a load balancer. Node Foreman can help you test the parallel capabilities of your application by spawning multiple processes behind a round-robin proxy.

$ nf start -x 8888 web=5
[OKAY] Starting Proxy Server 8888 -> 5000-5004

Access your application from port 8888 and the connections will be balanced across the servers started from ports 5000 - 5004.

If your application gets its port number from process.env.PORT the proxy setup will happen automatically.

Multiple Reverse Proxies

If you have multiple processes in your Procfile you can start multiple proxies.

$ nf start -x 8888,8080,9090

This will start 3 separate proxies and bind each to a separate process group. Proxies are bound based on their order specified, their order in the Procfile, or by their order on the command line.

$ nf start -x 8888,9999 web,api

Privileged Ports

Node Foreman disallows applications from starting on privileged ports. It does however allow proxies to be bound to lower ports, such as port 80.

If you require access to a privileged port, start Node Foreman with sudo:

$ sudo nf start -x 80 web=5
[OKAY] Starting Proxy Server 80 -> 5000-5004

Your application will then be accessible via port 80, but it will be running as root.

Forward Proxy

Local development and testing has huge advantages, but sometimes one needs to test web applications against their real-world domain name. Editing /etc/hosts is a pain however, and error prone.

Node Foreman can start up an HTTP forward proxy which your browser can route requests through. The forward proxy will intercept requests based on domain name, and route them to the local application.

$ nf start -f 9999 -i nodefly.com
[OKAY] Forward Proxy Started in Port 9999
[OKAY] Intercepting requests to nodefly.com through forward proxy

A forward proxy is useful when testing OAuth, or other external services with application callbacks.

For users with Google Chrome, this can be paired with FelisCatus SwitchyOmega for great results.

node-foreman's People

Contributors

ameliabradley avatar aripollak avatar bajtos avatar barbuza avatar briangonzalez avatar doublerebel avatar e-jigsaw avatar elgalu avatar foiseworth avatar groundwater avatar gutenye avatar iristyle avatar jeffjewiss avatar jeffkole avatar joeyespo avatar johngeorgewright avatar kainosnoema avatar larzconwell avatar nazarhussain avatar rmg avatar sam-github avatar sidwood avatar toastynerd avatar vyorkin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-foreman's Issues

0.0.20 / Versioning

Looks like NPM got a new version, but the matching commit didn't get pushed?

Might also want to start git tagging releases via push --tags

-e

Tests do not pass when using sed

The default BSD sed installed on a Mac OSX 10.11 (El Capitan) does not support multiple -e arguments, so the sed -i -e [...] -e [...] commands in test scripts do not run successfully. Installing gnu-sed solves the problem.

Would it be acceptable to change the scripts to fail loudly if gsed is not available, or invoke multiple sed commands to achieve the multiple substitutions?

Graceful shutdown?

Hey guys,

I'm considering node-foreman for our standard node tutorials on Heroku DevCenter, but I don't see anything here on graceful shutdowns. This is especially important for a lot of our customers who run worker processes.

What's the recommended way (if there is one?) of using node-foreman but allowing for graceful shutdowns locally when the user presses Cmd + C? If there isn't one, how would you feel about a PR?

Thanks!

Unwanted PATH in export

Hi,

Is there a reason why PATH always gets exported? It only seems to get in the way + prevents me from using the exported files on another machine... if I really wanted to change PATH, I'd just put it in .env.

unlinks a unexpectedly wide range of files when removing old exports

var x = file.indexOf(command.app);

I ran

nf export -a app-name ...

and node-foreman happily unlinked both my app-name.sublime-project and app-name.sublime-workspace files living in the project root. Perhaps nf should be more judicious and only unlink filenames that match the known patterns, something like:

app-name-(?:web|api)(?:-[0-9]+)?\.(?:conf|service|target|xml)

Child processes do not receive stdin

Example Procfile:

web: nodemon app.js
watch: grunt watch:dev

Nodemon supports typing "rs" to manually trigger a restart. When running nodemon as a child process of node-foreman, it seems that this input is not passed along; a restart is not triggered.

The foreman gem does support this. Would it be feasible for node-foreman to?

Thanks!

Procfile improvements

If you leave a comment in the Procfile using #, it works well in ruby foreman but throws a "Procfile not found" error for node foreman. It would be good if comments were supported in Procfile and also if the error reporting differentiates between a parse error and the Procfile not being found. I will probably open a pull request to resolve these issues.

Double-quotes in environment variable values aren't handled well

This happens with both JSON and KEY=VALUE format .env files. My environment contains a JSON literal, a list of regular expressions to match against email addresses:

ACCESS_LIST='["^[email protected]$"]'

In the JSON format, this would just be an array, rather than a string that contains a JSON array.

In either case, when writing /etc/init/my-upstart-config-web-1.conf, nf renders this variable as

env ACCESS_LIST="["^[email protected]$"]"

This makes it very hard to get the right value through to my program - if I escape the inner quotes with backslashes, somehow the backslashes come through, while if I don't, then the inner quotes are omitted completely. Ruby foreman renders this variable with surrounding single-quotes so that the inner double-quotes don't mess it up.

output bare console logs

Would it be possible the provide an option that would avoid appending timestamps and wrapping log lines?

Output trimming with colours

Hey there,

I've just noticed that the trimming length does not take in to account colours. For example, in the attached image you can see that the javascript.1 error description is cut very short because of all the colour changes. Event though the length is trimmed to 104 columns, it just says:

[L3:C34] W098: "$routeProvide...

When it should say:

[L3:C34] W098: '$routeProvider' is defined but never used.

trimming length

John

Ignoring PORT value is unexpected

node-foreman unexpectedly ignores a PORT value in a configuration file.

In this issue, @rmg stated that this was expected behavior, however this is not actually how foreman itself works. It will not override a PORT value specified in a configuration file.

port

I spent a while trying to find out why node-foreman was ignoring parts of my environment configuration before I found that old issue. Hopefully this behavior can be changed, or at least mentioned in the README.

This is problematic because it appears as though if I were to use the --proxy option, I have to supply ports for each process I'm running with node-foreman. If one of those doesn't actually require a port at all because it's not a server, this feels a little silly. Further it makes it difficult to start node-foreman with something like npm run dev, which is useful when node-foreman will be starting processes with commands from my node_modules/.bin directory.

More than anything, though, it's just a confusing deviation from foreman's standard behavior.

Errors produce 0 exit code.

Running nf and having it error results in process.exit(0) being called. It should be some non-zero exit code.

To reproduce:

nf export foo bar
echo $?

Will result in something like

[WARN] No ENV file found
[FAIL] Unknown Export Format undefined
0

Still supported?

Are you guys still supporting this?

If not, do you have another recommendation for process management?

Thx

# sign in .env

I have a password I use for development and I put it into the .env file. The problem I'm facing is that the password has the # character and node-foreman is considering it a comment. I also tried wrapping it into single quotes, as one would do in the shell, but I got even weirder results.

It seems like a somewhat easy fix, but I'm kinda short on time to get my head down and submit a PR.

Investigate: Exported Upstart scripts don't start on boot

It would appear that foreman and node-foreman follow the same basic template for the main Upstart conf.

Issue reports on the foreman issue tracker, have issuers noticing that the services aren't starting after a reboot.

I haven't had a chance to verify if this is correct or not... yet. But I thought it was worth getting the ball rolling at the very least.

See this in particular:
ddollar/foreman#263 (comment)

unknown command on windows

I don't know how NPM and bower do it, but foreman does not become a runnable command on windows after an npm install -g foreman.

export to systemd not working

$ nf export -t systemd

[OKAY] Loaded ENV .env File as KEY=VALUE Format
(node) Buffer.write(string, encoding, offset, length) is deprecated. Use write(string[, offset[, length]][, encoding]) instead.
[OKAY] Wrote  : foreman-web-1.service
[OKAY] Wrote  : foreman-web.target
[OKAY] Wrote  : foreman.target

$ cat foreman.target

[Unit]
Wants=foreman-.target

It should be

[Unit]
Wants=foreman-web.target

Mu2 should be replaced with a template engine that doesn't HTML escape

Ok, based on some bad stuff hapenning in #7 , this deserves a separate issue.

Currently Mu2 is being used... however, it has a major failing in that it HTML escapes, but does not allow you to disable the escaping.

https://github.com/raycmorgan/Mu/blob/master/lib/mu/renderer.js#L233

You really don't want this happening in system configuration text files.

function escapeReplace(char) {
  switch (char) {
    case '<': return '&lt;';
    case '>': return '&gt;';
    case '&': return '&amp;';
    case '"': return '&quot;';
    default: return char;
  }

So, there are a couple of possibilities here

Replace Mu2 with another mustache-esque parser

doT looks good enough.

I've verified that it works just fine, but it's not quite the same as Mustache, so there will need to be some minor changes to the templates. IMHO, not a big deal.

Unlike some of the other parsers / template engines, dot has no dependencies (and a full-blown NPM install is only about 17k). I took a look at Swig, but it weighed in at 500k installed with a dependency on underscore.

> var dot = require ('dot');
undefined
> var template = dot.template('do this && do that {{=it.thing}}');
undefined
> template({thing: 'the THING!'});
'do this && do that the THING!'

Hacky... keep using Mu2

Write a function that undoes the escaped text. I don't think that's a great option.

Crash if using -x and a connection is made before a process binds

I run my app locally using the following command:

nf start -x 4000 -j Procfile.local

If a connection is made during startup, when no process is bound to its port, the following exception is thrown:

/usr/lib/node_modules/foreman/node_modules/http-proxy/lib/http-proxy/index.js:119
    throw err;
          ^
Error: connect ECONNREFUSED
    at exports._errnoException (util.js:746:11)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)

After that, node-foreman immediately quits.

I have my processes run using nodemon so that changes are reflected immediately in the app, so I have to wait a few moments to even try to make a request so that it doesn't crash.

Is there a solution to this from my part? If not, a fix would be nice, even if it's just refusing the connection and continue, so that node-forman doesn't crash.

'setuid argument must be a number or a string' when running in Docker

How to reproduce:

  • Run nf start in Docker

The line in question is this:
https://github.com/strongloop/node-foreman/blob/master/nf.js#L100

if(process.getuid && process.getuid() === 0) {
  process.setuid(process.env.SUDO_USER);
}

My guess is that this is caused by the SUDO_USER variable being not set because the application runs user root user. I tried to put SUDO_USER=docker to my .env file, but the issue persists. Is there a workaround?

Start a Group of Modules

When nf start is run without a Procfile, and the current directory is not a module (i.e. no package.json file) Node Foreman attempts npm start in all sub-directories.

Can't use $PORT in Procfile

I'm getting errors like this trying to use a Procfile that works with the main version:

dev_db: ./node_modules/multicouch/bin/multicouch --port $PORT local_data

yields:

Unresovled Substitution in dev_db: $PORT

The code currently only passes the "global" environment variables to the Procfile parsing helper and the latter does not calculate ports while parsing.

Haven't looked into its source, but I imagine the Ruby version must fill out the arguments later (while starting each instance) rather than sooner.

How to export port 80 proxy?

Does the export functionality include proxy-ing from port 80 to the foreman web processes? I can't seem to use -x option with export.

Disable trimming *and* wrapping?

Hi folks,

I'm a new user to node-foreman, but really excited by it. Thanks for all the great work!

Like others, I ran into the discovery that logs get trimmed (truncated) by default. Feedback: that feels like a particularly unfriendly default to me.

I studied the code and discovered --wrap (as noted in issue #88), but I ran into issue #89 where this doesn't seem to actually work for me.

I thought okay, I'll just set the trim to be really high (e.g. --trim 99999999). But it turns out even then, the code wraps to 500 chars by default — with no way to override this:

this.wrapline = 500;

node-foreman/nf.js

Lines 84 to 93 in 52e9401

if(command.wrap) {
display.wrapline = process.stdout.columns - display.padding - 7;
display.trimline = 0;
display.Alert('Wrapping display Output to %d Columns', display.wrapline);
} else {
display.trimline = command.trim || process.stdout.columns - display.padding - 5;
if(display.trimline > 0){
display.Alert('Trimming display Output to %d Columns', display.trimline);
}
}

A 500-char wrap might sound reasonable, but wrapping in general is often undesirable to me:

11:19:41 AM api.1 |  ... meta={"reqType":"priv
11:19:41 AM api.1 |  >  ate"} that was hard to read
11:19:41 AM api.1 |  ... https://some_lo
11:19:41 AM api.1 |  >  ng_url that I used to be able to cmd+double-click

As noted in issue #33 (comment), wrapping feels unnecessary since the terminal already wraps natively (without breaking the log apart).

So I'd love a way to disable both trimming and wrapping. Thank you!

htProxy.RoutingProxy undefined is not a function error

deploy@server:~/oaa$ sudo nf start -x 80 -p 3000
[OKAY] Loaded ENV .env File as KEY=VALUE Format
[OKAY] Trimming display Output to 183 Columns
[OKAY] Starting Proxy Server [web] 80 -> 3000

/opt/bitnami/nodejs/lib/node_modules/foreman/proxy.js:20
var proxy = new htproxy.RoutingProxy();
            ^
TypeError: undefined is not a function
    at Object.<anonymous> (/opt/bitnami/nodejs/lib/node_modules/foreman/proxy.js:20:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
[DONE] Killing All Processes
[DONE] Killing Proxy Server on Port 80
03:39:13 web.1 |  Running on port 3000

it seems like according to http://stackoverflow.com/questions/21663601/how-to-write-a-node-express-app-that-serves-most-local-files-but-reroutes-some that the interface to htproxy has changed, causing this error?

Disable truncate feature

I'd like to be able to disable the new truncate feature. Especially if I have some error that like to read the full output from.

Can I do that currently or would that be a feature request?

On Windows 7 x64: '\"node web.js\"' is not recognized as an internal or external command...

I'm using node-forman because foreman start gives me "Error: write EINVAL"; some StackOverflow users with similar errors suggested using node-foreman.

Here is a screenshot with all the details:
image

If I run it with node web.js it works fine, but fails immediately if I try using nf web.js

My Procfile:
web: node web.js

Misc other info
I'm using express.js 4.8.3
node --version is v0.10.30
nf --version is 0.4.1
npm --version is 1.2.18

Let me know if there is anything I can do or any more information you may need.

Use an environment variable to determine which Procfile to use

If no Procfile exists in the root dir, and if not Procfile is defined via -f argument, it would be helpful if foreman checked an environment variable for which Procfile to use. This would allow our organization to easily define different Procfiles for dev, test, staging, etc.

Key PORT not being picked from .env file

Windows 7 : I have a key PORT in .env file.

nf does not use the value in .env file. Rather it uses a default of 5000.

Please confirm if this behavior is correct.

Preserve indentation in original output

It looks as if node-foreman trims everything. It should preserve indentation, as it might be meaningful.

I have a Procfile that does two things: 1) continuously compile LiveScript to JavaScript, 2) runs tests whenever a JavaScript file changes. The test output is indented, e.g. with Mocha’s spec reporter (http://mochajs.org/#reporters).

Configurable log location for export command

For feature parity with the Ruby version of Foreman, it would be helpful to support a configurable -l for log location.

I'd like to switch over to your variant, since I prefer Node... but we're Capistrano deploying, and Capistrano configures log directories already, so it's nice to be able to pass that to export.

http://ddollar.github.com/foreman/#EXPORTING

You're missing a few other options there, but we don't need those at the moment.. just the log location for now ;0

Thanks!

Environmental variables in Procfile

I noticed you can't use Env variables in Procfiles, I was using the Ruby foreman Gem and it did enable the use of variables in Procfiles. I was wondering if you were interested in that feature?

I want to use a env file and load an environment variable so that a command in the Procfile can load the correct file according to the environment var. Though I'm not sure this is possible currently because I think it's loading the Procfile before the envs https://github.com/NodeFly/node-foreman/blob/master/nf.js#L68-72

Proxy error under MS Windows - Object #<process> has no method 'getuid'

In MS Windows, running nf start -j Procfile2 -x $PORT web=2,worker=2, I got the following error:

    d:\gitproj\njsproj\node-articles-nlp-redis-queue\node_modules\foreman\proxy.js:42
         if(process.getuid()==0) process.setuid( process.env.SUDO_USER );
                ^
    TypeError: Object #<process> has no method 'getuid'
       at Server.<anonymous> (d:\gitproj\njsproj\node-articles-nlp-redis-queue\node_modules\foreman\proxy.js:42:16)
       at Server.g (events.js:180:16)
       at Server.emit (events.js:92:17)
       at net.js:1055:10
       at process._tickCallback (node.js:419:13)
       at Function.Module.runMain (module.js:499:11)
       at startup (node.js:119:16)
       at node.js:906:3

I fixed this by making the proxy.js listen callback test for MS Windows:

    // Main HTTP Server
    http.createServer(function (req, res) {
            var target = addresses.shift();
            proxy.web(req, res, {target: target});
        addresses.push(target);
    }).listen(port,function(){
            if(process.platform.substring(0,3) !== 'win') {
               if(process.getuid()==0) process.setuid( process.env.SUDO_USER );
            }
    })

Programmatic API

I'm trying to integrate foreman into a workflow tool. The tool uses a task runner (gulp) to orchestrate commands across multiple projects. It would make a lot of sense to invoke foreman directly from javascript, rather than through child_process hoops. While this is already possible, the api surface could be a lot tighter.

How about a refactor, turning this into a javascript facing module that happens to have a commander wrapper?

environment variables don't seem to be getting picked up under supervisord

node-foreman works very well for me in development, but I'm having problems with an Export to Production. I run

nf export --type supervisord --user ubuntu

and get a foreman-web-1.conf file that looks like:

[program:foreman-web-1]
command=npm start
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/var/log/foreman-web-1.stdout.log
stderr_logfile=/var/log/foreman-web-1.stderr.log
user=ubuntu
directory=/home/sites/site-root
environment=PORT="3000",API_HOST="api.example.com",USER="user",PASS="password",SES_USER="ses_user",SES_PASS="ses_pass",SES_SMTP_HOST="email-smtp.us-west-2.amazonaws.com",SES_SMTP_PORT="587",RECAPTCHA_SITE_KEY="site_key",RECAPTCHA_SECRET="secret",FEEDBACK="[email protected]",PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games",PORT="3000",FOREMAN_WORKER_NAME="web.1"

But the environment variables don't get through to the application.

/home/sites/site-root/node_modules/express-recaptcha/lib/express-recaptcha.js:27
  if (!this.site_key) throw new Error('site_key is required');
                            ^
Error: site_key is required

I thought I'd been using API_HOST all along, but in struggling with the recaptcha stuff today I realize that I hard coded its value prior to a demo and it may never have worked. But starting the app with nf start works just fine.

Any suggestions as to what I'm missing would be much appreciated, thanks.

npm "latest" should be versioned

NPM warns me about how you are declaring dependencies:

npm WARN unmet dependency ../node_modules/foreman requires commander@'latest' but will load
npm WARN unmet dependency ../node_modules/commander,
npm WARN unmet dependency which is version 1.1.1

Use setgid in Upstart template / setuid only sets primary user group

TL; DR

The template for the Upstart job needs to have setgid (at least optionally) in addition to setuid

https://github.com/NodeFly/node-foreman/blob/master/lib/upstart/foreman-APP-N.conf#L11

The longer version ;0

I'm using Capistrano to deploy. Capistrano has kind of an architectural issue, where it expects the deploying user to be the same user as the one an application runs as.

This is a bad practice from a security standpoint, so I have it changed up a little bit to follow a more locked-down / secure setup. It's pretty similar to what's written in this SO answer.

  • Deploying user is the standard ubuntu user on our EC2 vm
  • An app has it's own foo account, where it's only allowed read access to the directories it needs. The exception is that the log directory can be written to.
  • The ubuntu user and the foo user are both made part of the deployers group, so that we can actually deploy the app.
  • Because sudo needs to be used at times during deploy, it's best done with this deploying ubuntu user rather than the apps foo user.

In any event, this setup works fine with the stock Ruby foreman, because the generated upstart script runs exec su - foo -c "commands". Node-foreman is a little more modern with its setup and uses the setuid stanza (available on Upstart 1.4+).

The problem with setuid is that it only sets up the primary user group. This is filed as a bug in Upstart, but the patch hasn't been integrated.

As soon as I added the setgid to my Upstart conf I was in business.

setgid deployers

Another alternative

I don't know a ton about Upstart, but perhaps the old foreman style is generally more compatible than how yours is rigged up. Your version is much more readable for what it's worth.

Issues with Multiple Reverse Proxy

I am facing problem with multiple reverse proxies. It is not functioning as per described in Readme.

I have following Procfile.

app: node app.js | bunyan
api: node api.js | bunyan

Now I run it with:

nf start -x 3000,4000 app=3,api=2

And the output that came out and cause error onward.

[WARN] No ENV file found
[OKAY] Trimming display Output to 136 Columns
[OKAY] Starting Proxy Server [app] 3000 -> (5000-5002)
[OKAY] Starting Proxy Server [api] 3000 -> (5000-5001)

As you can see cleary there are two issues:

  1. It does not pick right port group for right process, only uses first that was specified
  2. Second it uses same output port group for all jobs.

It seems something is clearly broken. Please help me out to troubleshoot the issue.

Thanks.

$PORT Not Set

The orignal (Ruby) version of foreman automatically sets the PORT environment variable for each process, so that it can be used in your Procfile. It would be nice to have the same functionality here.

Related: #20

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.