Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socketpath #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ The `up` command accepts the following options:
- The port to listen on. Not required if the module already `listen`s.
- Defaults to `3000`.

- `-s`/`--socketpath`

- The unix domain socket path to listen on. Not required if the module already `listen`s.
- Cannot be set, if `port` is specified.

- `-w`/`--watch`

- Whether to watch for changes.
Expand Down
19 changes: 16 additions & 3 deletions bin/up
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var cpus = require('os').cpus().length;
program
.version(up.version)
.usage('[options] <file>')
.option('-p, --port <port>', 'Port to listen on.', 3000)
.option('-p, --port <port>', 'Port to listen on.')
.option('-s, --socketpath <path>', 'Unix domain socketpath to listen on.')
.option('-T, --title <title>', 'Process title.', 'up')
.option('-f, --pidfile <pidfile>', 'Write port to pidfile')
.option('-w, --watch', 'Watch the module directory for changes.')
Expand Down Expand Up @@ -108,12 +109,20 @@ if (!(server instanceof http.Server)) {

var port;

if (null != program.port && null != program.socketpath) {
error('\n Cannot specify both port and socketpath');
}

if (null != program.port) {
port = Number(program.port);

if (!port || isNaN(port)) {
error('\n Invalid port "%s" (%d).\n', program.port, program.port);
}
} else if (null != program.socketpath) {
port = program.socketpath;
} else {
port = 3000;
}

/**
Expand Down Expand Up @@ -148,11 +157,15 @@ var keepAlive = program.keepalive;
* Start!
*/

debug('starting cluster with %d workers on port %d', numWorkers, port);
if (typeof port == "number") {
debug('starting cluster with %d workers on port %d', numWorkers, port);
} else {
debug('starting cluster with %d workers on socket path %s', numWorkers, port);
}
debug('`\033[97mkill -s SIGUSR2 %d\033[90m` or \033[97mctrl + r\033[90m'
+ ' to load new code', process.pid);

var httpServer = http.Server().listen(program.port)
var httpServer = http.Server().listen(port)
, srv = up(httpServer, file, {
numWorkers: numWorkers
, workerTimeout: workerTimeout
Expand Down