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

allow binding to unix domain sockets #17

Open
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ 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.
- Cannot be set if port is specified.

- `-w`/`--watch`

- Whether to watch for changes.
Expand Down
20 changes: 16 additions & 4 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 <socketpath>', 'Socket path to listen on.')
.option('-f, --pidfile <pidfile>', 'Write port to pidfile')
.option('-w, --watch', 'Watch the module directory for changes.')
.option('-r, --require <file>', 'Module to require from each worker.')
Expand Down Expand Up @@ -103,7 +104,18 @@ if (!(server instanceof http.Server)) {

var port;

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


if (null == program.port) {
if (null == program.socketpath) {
port = 3000;
} else {
port = program.socketpath;
}
} else {
port = Number(program.port);

if (!port || isNaN(port)) {
Expand Down Expand Up @@ -137,11 +149,11 @@ if (null != workerTimeout && isNaN(ms(workerTimeout))) {
* Start!
*/

debug('starting cluster with %d workers on port %d', numWorkers, port);
debug('starting cluster with %d workers on port %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