node-persistent-software
Advanced tools
+28
-26
@@ -6,11 +6,12 @@ | ||
| const spawn = require("child_process").spawn, | ||
| events = require("asynchronous-eventemitter"); | ||
| const spawn = require("child_process").spawn; | ||
| // module | ||
| module.exports = class PersistantSoftware { | ||
| module.exports = class PersistantSoftware extends require("asynchronous-eventemitter") { | ||
| constructor(software, args, options) { | ||
| super(); | ||
| this.software = software; | ||
@@ -26,13 +27,4 @@ this.args = ("object" === typeof args && args instanceof Array) ? args : null; | ||
| this.eventEmitter = new events().on("eventerror", (err) => { | ||
| this.eventEmitter.emit("error", err); | ||
| }); | ||
| } | ||
| on(eventName, listener) { | ||
| this.eventEmitter.on(eventName, listener); | ||
| return this; | ||
| } | ||
| max(max) { | ||
@@ -65,3 +57,3 @@ this.maxCountRun = max; | ||
| this.currentChildProcess.on("error", (err) => { | ||
| this.eventEmitter.emit("error", err); | ||
| this.emit("error", err); | ||
| }); | ||
@@ -77,13 +69,13 @@ | ||
| if (1 < this.successCountRun) { | ||
| this.eventEmitter.emit("restart"); | ||
| this.emit("restart"); | ||
| } | ||
| else { | ||
| this.eventEmitter.emit("firststart"); | ||
| this.emit("firststart"); | ||
| } | ||
| this.eventEmitter.emit("start", this.currentChildProcess); | ||
| this.emit("start", this.currentChildProcess); | ||
| this.currentChildProcess.on("exit", () => { | ||
| this.eventEmitter.emit("stop"); | ||
| this.emit("stop"); | ||
@@ -109,3 +101,3 @@ if (!this.ended) { | ||
| catch(e) { | ||
| this.eventEmitter.emit("error", e); | ||
| this.emit("error", e); | ||
| } | ||
@@ -121,15 +113,25 @@ | ||
| if (this.currentChildProcess && this.currentChildProcess.pid) { | ||
| if (this.currentChildProcess) { | ||
| try { | ||
| process.kill(this.currentChildProcess.pid); | ||
| this.eventEmitter.emit("stop"); | ||
| if (this.currentChildProcess.pid) { | ||
| try { | ||
| process.kill(this.currentChildProcess.pid); | ||
| } | ||
| catch (e) { | ||
| // nothing to do here | ||
| } | ||
| } | ||
| catch (e) { | ||
| // nothing to do here | ||
| } | ||
| this.currentChildProcess = null; | ||
| } | ||
| this.eventEmitter.emit("end"); | ||
| this.emit("end") | ||
| .removeAllListeners("start") | ||
| .removeAllListeners("firststart") | ||
| .removeAllListeners("restart") | ||
| .removeAllListeners("stop") | ||
| .removeAllListeners("end"); | ||
@@ -136,0 +138,0 @@ return this; |
+1
-6
| { | ||
| "name": "node-persistent-software", | ||
| "version": "1.1.1", | ||
| "version": "1.2.0", | ||
| "description": "Spawn a software and keep it running", | ||
@@ -34,16 +34,11 @@ "main": "dist/main.js", | ||
| "devDependencies": { | ||
| "gulp": "^3.9.1", | ||
| "gulp-plumber": "^1.1.0", | ||
| "gulp-eslint": "^3.0.1", | ||
| "gulp-mocha": "^4.3.1", | ||
| "pre-commit": "^1.2.2", | ||
| "gulp-babel": "^6.1.2", | ||
| "babel-preset-es2015": "^6.24.1" | ||
| }, | ||
| "homepage": "https://github.com/Psychopoulet/node-persistent-software#readme" | ||
| } |
+1
-2
@@ -11,3 +11,3 @@ # node-persistent-software | ||
| ## Doc | ||
| ## Doc (extends : [asynchronous-eventemitter](https://www.npmjs.com/package/asynchronous-eventemitter)) | ||
@@ -35,3 +35,2 @@ ### Attributes | ||
| * ``` end() : this ``` stop the software and don't restart it | ||
| * ``` on(string eventName, function callback) : this ``` | ||
@@ -38,0 +37,0 @@ ### Events |
+2
-2
@@ -6,4 +6,4 @@ | ||
| const assert = require("assert"), | ||
| PersistantSoftware = require(require("path").join(__dirname, "..", "dist", "main.js")); | ||
| const assert = require("assert"); | ||
| const PersistantSoftware = require(require("path").join(__dirname, "..", "dist", "main.js")); | ||
@@ -10,0 +10,0 @@ // tests |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
16959
-0.64%108
-0.92%