diff --git a/package.json b/package.json index 391264b..dc3a701 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "fs-extra": "^1.0.0", "md5": "^2.2.1", "mkdirp": "^0.5.1", - "pm2": "^2.3.0" + "pm2": "^2.3.0", + "ps-node": "^0.1.4" } } diff --git a/routes/shepherd.js b/routes/shepherd.js index 74ccecc..be3df60 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -8,10 +8,12 @@ const fsnode = require('fs'); const fs = require('fs-extra'); const mkdirp = require('mkdirp'); const express = require('express'); +const exec = require('child_process').exec; const md5 = require('md5'); const pm2 = require('pm2'); Promise = require('bluebird'); const fixPath = require('fix-path'); +var ps = require('ps-node'); var setconf = require("../private/setconf.js"); @@ -152,6 +154,32 @@ function herder(flock, data) { console.log('iguana flock selected...'); console.log('selected data: '+data); + //Make sure iguana isn't running before starting new process, kill it dammit! + // A simple pid lookup + /*ps.lookup({ + command: 'iguana', + //arguments: '--debug', + }, function(err, resultList ) { + if (err) { + throw new Error( err ); + } + resultList.forEach(function( process ){ + if( process ){ + console.log( 'PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments ); + console.log(process.pid); + // A simple pid lookup + ps.kill( process.pid, function( err ) { + if (err) { + throw new Error( err ); + } + else { + console.log( 'Process %s has been killed!', process.pid ); + } + }); + } + }); + });*/ + // MAKE SURE IGUANA DIR IS THERE FOR USER mkdirp(iguanaDir, function (err) { if (err)