Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Node module for easy creation of daemons for Node 0.8.x and above.
For Node 0.6.x compatibility see daemonize https://github.com/niegowski/node-daemonize
Just write your daemon as plain node.js application
(like /examples/simple/app.js
) and a simple controller with Daemonize
(like /examples/simple/ctrl.js
).
$ npm install daemonize2
var daemon = require("daemonize2").setup({
main: "app.js",
name: "sampleapp",
pidfile: "sampleapp.pid"
});
switch (process.argv[2]) {
case "start":
daemon.start();
break;
case "stop":
daemon.stop();
break;
default:
console.log("Usage: [start|stop]");
}
For more examples see examples
folder.
Daemonize works like standard require()
but loaded module is
forked to work in background as a daemon.
Keep in mind that stdin
, stdout
and stderr
are redirected
to /dev/null
so any output from daemon won't display in console.
You need to use file for logging (ie like /examples/advanced/app.js
).
Also any uncaught exception won't be displayed in the console,
so process.on("uncaughtException", ...)
should be used to
redirect output to some log file.
Creates new Daemon
instance. Supported options
:
main
- main application module file to run as daemon (required); string
name
- daemon name (default: basename of main); string
pidfile
- pidfile path (default: /var/run/[name].pid
); string
user
- name or id of user (default: current); string
group
- name or id of group (default: current); string
umask
- file mode mask (default: 0); number
or string
silent
- disable printing info to console (default: false
); boolean
stopTimeout
- interval (ms) of daemon killing retry (default: 2s
); number
args
- additional node runtime arguments, ie --debug
; array
or string
argv
- argv for daemon (default: process.argv.slice(2)
); array
or string
All paths are resolved relative to file that uses "daemonize".
All commandline arguments will be passed to the child process unless
overriden with argv
option.
Daemon control class. It references controlled daemon.
function() { }
Emitted when start()
is called and if daemon is not already running.
function(pid) { }
Emitted when daemon successfully started after calling start()
.
function(pid) { }
Emitted when start()
is called and a daemon is already running.
function() { }
Emitted when stop()
or kill()
is called and a daemon is running.
function(pid) { }
Emitted when daemon was successfully stopped after calling stop()
or kill()
.
function() { }
Emitted when stop()
or kill()
is called and a deamon is not running.
function(error) { }
Emitted when start()
failed. error
is instance of Error
.
error.message
contains information what went wrong.
Start daemon asynchronously. Emits running
in case when daemon is
already running and starting
when daemon is not running. Then emits
started
when daemon is successfully started.
Optional listener
callback is once called on running
, started
or error
event. The callback gets two arguments (err, pid)
.
Emits error
in case of any problem during daemon startup.
Asynchronously stop daemon. Sends SIGTERM
to daemon every 2s (or time
set in options).
Emits notrunning
when daemon is not running, otherwise
emits stopping
and then stopped
when daemon successfully stopped.
Optional listener
callback is once called on notrunning
, stopped
or
error
event. The callback gets two arguments (err, pid)
.
Kill daemon asynchronously. Sends SIGTERM
and after 2s SIGKILL
to the
child if needed. Repeats sending SIGKILL
every 2s untill daemon
stops (interval can be changed in options).
Emits events same as stop()
.
Optional listener
callback is same as stop
.
Synchronously returns pid for running daemon or 0 when daemon is not running.
Synchronously sends signal
to daemon and returns pid of daemon or 0 when
daemon is not running.
Daemonize is maintained under the [Semantic Versioning] (https://github.com/niegowski/semver/blob/master/semver.md) guidelines.
args
and argv
on whitespacesumask
option(The MIT License)
Copyright (c) 2012 Kuba Niegowski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Module for easy creation of daemons for Node 0.8.x
We found that daemonize2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.