Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Creates new `Daemon` instance. Supported `options`:
* `args` - additional node runtime arguments, ie `--debug`; `array` or `string`
* `argv` - argv for daemon (default: `process.argv.slice(2)`); `array` or `string`
* `cwd` - current working directory for spawned daemon (default: `/`); `string`
* `fds` - array of additional file descriptors to pass to the daemon. Note that the actual descriptors passed to the daemon are `[ 'ignore', 'ignore', 'ignore', 'ipc' ].concat(fds)`, so the supplied descriptors will be available in the daemon as starting from fd 4. For more information look at [Node docs](https://nodejs.org/api/child_process.html#child_process_options_stdio).

All paths are resolved relative to file that uses "daemonize".

Expand Down
6 changes: 5 additions & 1 deletion lib/daemonize.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ var Daemon = function(options) {
this._options.user = options.user || "";
this._options.group = options.group || "";

this._options.fds = options.fds || [];
if (!Array.isArray(this._options.fds))
this._options.fds = [ this._options.fds ];

if (typeof options.umask == "undefined")
this._options.umask = 0;
else if (typeof options.umask == "string")
Expand Down Expand Up @@ -121,7 +125,7 @@ Daemon.prototype.start = function(listener) {
__dirname + "/wrapper.js"
]).concat(this._options.argv), {
env: process.env,
stdio: ["ignore", "ignore", "ignore", "ipc"],
stdio: ["ignore", "ignore", "ignore", "ipc"].concat(this._options.fds),
detached: true
}
);
Expand Down