pm2
Advanced tools
Comparing version 0.4.14 to 0.5.0
[{ | ||
"name" : "echo", | ||
"script" : "./examples/echo.js", | ||
"max" : "10" | ||
},{ | ||
"name" : "api", | ||
"script" : "./examples/child.js", | ||
"instances" : "4" | ||
},{ | ||
"name" : "bus", | ||
"script" : "./examples/echokill.js" | ||
"name" : "echo", | ||
"script" : "./examples/args.js", | ||
"instances" : "1", | ||
"args" : "['--toto=heya coco', '-d', '1']", | ||
"cron_restart" : "* * * * * *" | ||
}] |
@@ -18,4 +18,3 @@ | ||
DEBUG : false, | ||
WEB_INTERFACE : 9615, | ||
MS_TO_STOP_SCRIPT : 1000 | ||
WEB_INTERFACE : 9615 | ||
}; |
process.argv.forEach(function (val, index, array) { | ||
console.log(index + ': ' + val); | ||
}); | ||
setInterval(function() { | ||
console.log('HERE ARE MY ARGS !!! = ', process.argv); | ||
}, 800); | ||
@@ -36,19 +36,8 @@ // pm2-monitor // Code name : God | ||
God.clusters_db[clu.pm_id].status = 'starting'; | ||
// Keep track of the number of restarts | ||
God.clusters_db[clu.pm_id].opts.restart_time = God.clusters_db[clu.pm_id].opts.restart_time + 1; | ||
if (clu.opts.max !== undefined) { | ||
if (clu.opts.max <= 0) { | ||
God.clusters_db[clu.pm_id].status = 'stopped'; | ||
delete God.clusters_db[clu.pm_id]; | ||
return ; | ||
} | ||
else clu.opts.max -= 1; | ||
} | ||
var stopped = God.clusters_db[clu.pm_id].process.pid == -1 ? true : false; | ||
delete God.clusters_db[clu.pm_id]; | ||
execute(clu.opts); | ||
if (!stopped) execute(clu.opts); | ||
}); | ||
@@ -84,2 +73,4 @@ })(); | ||
usage.lookup(pro.pid, { keepHistory : true }, function(err, res) { | ||
if (err) return cb(err); | ||
pro['monit'] = res; | ||
@@ -148,3 +139,2 @@ arr.push(pro); | ||
God.startProcess = function(clu, cb) { | ||
God.clusters_db[clu.pm_id].opts.max = 99; | ||
execute(God.clusters_db[clu.pm_id].opts, cb); | ||
@@ -158,3 +148,2 @@ }; | ||
return cb({ msg : "Process already online"}, {}); | ||
God.clusters_db[id].opts.max = 99; | ||
return execute(God.clusters_db[id].opts, cb); | ||
@@ -164,6 +153,7 @@ }; | ||
God.stopProcess = function(clu, cb) { | ||
God.clusters_db[clu.pm_id].opts.max = 0; | ||
if (God.clusters_db[clu.pm_id].status != 'stopped') | ||
if (!God.clusters_db[clu.pm_id]) return cb(); | ||
if (God.clusters_db[clu.pm_id].status != 'stopped'){ | ||
process.kill(God.clusters_db[clu.pm_id].process.pid); | ||
God.clusters_db[clu.pm_id].process.pid = 0; | ||
} | ||
God.clusters_db[clu.pm_id].process.pid = -1; | ||
setTimeout(cb, 200); | ||
@@ -175,5 +165,5 @@ }; | ||
return cb({msg : 'Process not found'}); | ||
God.clusters_db[id].opts.max = 0; | ||
//God.clusters_db[id].opts.max = 0; | ||
process.kill(God.clusters_db[id].process.pid); | ||
God.clusters_db[id].process.pid = 0; | ||
God.clusters_db[id].process.pid = -1; | ||
setTimeout(function() { | ||
@@ -180,0 +170,0 @@ cb(null, null); |
@@ -26,5 +26,9 @@ // pm2-htop | ||
if (processes[0].monit == null || processes[0].monit == undefined) | ||
throw new Error('You seems to run on a Mac OS, node-usage can\'t get monitor data'); | ||
if (!processes[0].monit) | ||
throw new Error('No monit assigned to processes'); | ||
if (processes[0].monit.error) | ||
throw new Error(JSON.stringify(processes[0].monit.error)); | ||
Monit.multi = multimeter(process); | ||
@@ -31,0 +35,0 @@ |
@@ -1,2 +0,2 @@ | ||
// God. | ||
// ProcessContainer.js | ||
// Child wrapper. Redirect output to files, assign pid & co. | ||
@@ -11,4 +11,4 @@ // by Strzelewicz Alexandre | ||
(function ProcessContainer() { | ||
var fs = require('fs'); | ||
var worker = require('cluster').worker; | ||
var fs = require('fs'); | ||
var worker = require('cluster').worker; | ||
@@ -21,7 +21,11 @@ var outFile = process.env.pm_out_log_path; | ||
var cronRestart = process.env.cron_restart; | ||
fs.writeFileSync(pidFile, process.pid); | ||
// Add args to process if args specified on start | ||
if (process.env.args != null) | ||
process.argv = process.argv.concat(process.env.args.split(' ')); | ||
process.argv = process.argv.concat(eval(process.env.args)); | ||
// Rename process | ||
@@ -32,4 +36,22 @@ if (process.env.name != null) | ||
exec(script, outFile, errFile); | ||
if (cronRestart) | ||
cronize(cronRestart); | ||
})(); | ||
// | ||
// Cron pattern like to force app to restart | ||
// | ||
function cronize(cron_pattern) { | ||
var cronJob = require('cron').CronJob; | ||
var job = new cronJob({ | ||
cronTime: cron_pattern, | ||
onTick: function() { | ||
process.exit(0); | ||
}, | ||
start: false | ||
}); | ||
job.start(); | ||
} | ||
function exec(script, outFile, errFile) { | ||
@@ -36,0 +58,0 @@ // Change dir to fix process.cwd |
var rpc = require("axon-rpc"); | ||
var axon = require("axon"); | ||
var rep = axon.socket("rep"); | ||
var req = axon.socket("req"); | ||
var debug = require("debug")("god:satan"); | ||
// | ||
// Satan is splitted in two parts. | ||
// - The first one is a daemon wrapper around God.js | ||
// which acts as an RPC server | ||
// => Satan.remoteWrapper | ||
// | ||
// - The other part is an RPC client which is mainly | ||
// used by the CLI | ||
// | ||
// by Strzelewicz Alexandre | ||
var rpc = require("axon-rpc"); | ||
var axon = require("axon"); | ||
var rep = axon.socket("rep"); | ||
var req = axon.socket("req"); | ||
var debug = require("debug")("god:satan"); | ||
var events = require("events"); | ||
var util = require("util"); | ||
var fs = require("fs"); | ||
var p = require("path"); | ||
var cst = require('../constants.js'); | ||
var util = require("util"); | ||
var fs = require("fs"); | ||
var p = require("path"); | ||
var cst = require('../constants.js'); | ||
@@ -41,2 +52,3 @@ // | ||
delete process.env.DAEMON; | ||
process.title = "pm2: Satan Daemonizer"; | ||
Satan.remoteWrapper(); | ||
@@ -47,3 +59,9 @@ } | ||
if (ab == false) | ||
return Satan.launchDaemon(Satan.launchRPC); | ||
return Satan.launchDaemon(function(err, child) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
Satan.launchRPC(); | ||
}); | ||
return Satan.launchRPC(); | ||
@@ -187,3 +205,3 @@ }); | ||
console.log(msg); | ||
return setTimeout(function() {cb(child)}, 100); // Put a little time out | ||
return setTimeout(function() {cb(null, child)}, 100); // Put a little time out | ||
}); | ||
@@ -190,0 +208,0 @@ }; |
{ | ||
"name": "pm2", | ||
"preferGlobal": "true", | ||
"version": "0.4.14", | ||
"version": "0.5.0", | ||
"engines" : { | ||
@@ -23,4 +23,4 @@ "node" : ">=0.8" | ||
}], | ||
"homepage" : "http://unitech.io/", | ||
"description": "The next generation process manager for Node.js with native clusterization ", | ||
"homepage" : "https://github.com/Unitech/pm2", | ||
"description": "The modern CLI process manager for Node apps with native clusterization", | ||
"main": "index.js", | ||
@@ -43,3 +43,4 @@ "scripts": { | ||
"cluster cli", | ||
"cluster" | ||
"cluster", | ||
"cron" | ||
], | ||
@@ -50,10 +51,11 @@ "bin": { | ||
"dependencies": { | ||
"commander": "1.1.0", | ||
"cli-table" : "0.2.0", | ||
"multimeter": "git://github.com/Unitech/node-multimeter.git", | ||
"usage" : "0.3.5", | ||
"axon-rpc" : "0.0.2", | ||
"watch" : "0.7.0", | ||
"axon" : "0.6.1", | ||
"debug" : "*" | ||
"commander" : "1.1.0", | ||
"cli-table" : "0.2.0", | ||
"multimeter" : "git://github.com/Unitech/node-multimeter.git", | ||
"usage" : "0.3.7", | ||
"axon-rpc" : "0.0.2", | ||
"watch" : "0.7.0", | ||
"axon" : "0.6.1", | ||
"debug" : "*", | ||
"cron" : "1.0.1" | ||
}, | ||
@@ -60,0 +62,0 @@ "devDependencies": { |
@@ -7,7 +7,6 @@ ![Monit](https://github.com/unitech/pm2/raw/master/pres/pm22.png) | ||
The next generation daemon process manager for Node.js with native clusterization. | ||
The modern CLI process manager for Node apps with native clusterization. | ||
PM2 is mainly a production module for Linux servers. | ||
Tested with Node v0.8, v0.10, v0.11 | ||
Works on Linux & MacOS | ||
@@ -49,2 +48,6 @@ # Installation | ||
$ pm2 start app.js -c "* * * * * *" # Will restart the process depending on the | ||
# cron pattern. Here it will restart the process | ||
# every second | ||
$ pm2 start app.js -i max -- -a 23 # Pass arguments after -- to app.js | ||
@@ -76,2 +79,13 @@ $ pm2 start app.js -i max -e err.log -o out.log -w # Will start and generate a configuration file | ||
## How to install the pm2 master branch | ||
```bash | ||
npm install git://github.com/Unitech/pm2.git -g | ||
``` | ||
## pm2 context | ||
pm2 permits you to daemonize node.js scripts very easily. | ||
All processes popped with pm2 inherit the entire environment. | ||
## pm2 list | ||
@@ -102,2 +116,6 @@ | ||
## pm2 cron restart | ||
The `-c "cron_pattern"` option permits to hard restart a process scheduled on the cron pattern. | ||
## pm2 health web api endpoint | ||
@@ -131,7 +149,7 @@ | ||
[{ | ||
"name" : "echo", | ||
"script" : "./examples/echo.js", | ||
"max" : "10", | ||
"instances" : "max", | ||
"args" : "-d 1" | ||
"name" : "echo", | ||
"script" : "./examples/args.js", | ||
"instances" : "1", | ||
"args" : "['--toto=heya coco', '-d', '1']", | ||
"cron_restart" : "* * * * * *" | ||
},{ | ||
@@ -138,0 +156,0 @@ "name" : "api", |
if (process.argv.indexOf('-d') < -1) { | ||
if (process.argv.indexOf('-d') == -1 || process.argv.indexOf('-a') == -1) { | ||
process.exit(); | ||
@@ -5,0 +5,0 @@ } else { |
@@ -20,3 +20,3 @@ | ||
describe('One process', function() { | ||
var proc; | ||
var proc, pid; | ||
@@ -35,2 +35,3 @@ after(function(done) { | ||
proc = proce; | ||
pid = proc.process.pid; | ||
proc.status.should.be.equal('online'); | ||
@@ -47,5 +48,4 @@ God.getFormatedProcesses().length.should.equal(1); | ||
God.getFormatedProcesses().length.should.equal(0); | ||
God.checkProcess(proc.process.pid).should.be.false; | ||
proc.status.should.be.equal('stopped'); | ||
done() | ||
God.checkProcess(pid).should.be.false; | ||
done(); | ||
}); | ||
@@ -100,3 +100,3 @@ }); | ||
pm_pid_path : path.resolve(process.cwd(), 'test/child'), | ||
args : '-d -a', | ||
args : "['-d', '-a']", | ||
instances : '1' | ||
@@ -106,11 +106,25 @@ }, function(err, procs) { | ||
God.getFormatedProcesses()[0].opts.restart_time.should.eql(0); | ||
console.log(God.getFormatedProcesses()[0]); | ||
God.stopAll(done); | ||
}, 400); | ||
}, 500); | ||
}); | ||
}); | ||
it('should cron restart', function(done) { | ||
God.prepare({ | ||
pm_exec_path : path.resolve(process.cwd(), 'test/fixtures/args.js'), | ||
pm_err_log_path : path.resolve(process.cwd(), 'test/errLog.log'), | ||
pm_out_log_path : path.resolve(process.cwd(), 'test/outLog.log'), | ||
pm_pid_path : path.resolve(process.cwd(), 'test/child'), | ||
args : "['-d', '-a']", | ||
cron_restart : '* * * * * *', | ||
instances : '1' | ||
}, function(err, procs) { | ||
setTimeout(function() { | ||
God.getFormatedProcesses()[0].opts.restart_time.should.be.above(1); | ||
God.stopAll(done); | ||
}, 2200); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -26,3 +26,4 @@ | ||
it('should start daemon', function(done) { | ||
Satan.launchDaemon(function(child) { | ||
Satan.launchDaemon(function(err, child) { | ||
assert(err == null); | ||
assert(typeof child.pid == 'number'); | ||
@@ -29,0 +30,0 @@ Satan.pingDaemon(function(online) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
463384
58
1198
221
9
23
5
+ Addedcron@1.0.1
+ Addedcron@1.0.1(transitive)
+ Addedusage@0.3.7(transitive)
- Removedusage@0.3.5(transitive)
Updatedusage@0.3.7