Created
August 22, 2013 22:03
-
-
Save markcode/6313391 to your computer and use it in GitHub Desktop.
Kurunt Launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Kurunt Launch | |
// | |
// Launches node.js apps through /etc/init.d/. | |
// Version: 0.1 | |
// Author: Mark W. B. Ashcroft | |
// | |
// Copyright (c) 2013 Mark W. B. Ashcroft. | |
// Copyright (c) 2013 Kurunt. | |
// | |
var util = require('util'); | |
var exec = require('child_process').exec; | |
var LOGGING = 'quiet'; | |
function _log(a,b){"debug"===LOGGING&&void 0!==b?console.log("debug - "+a+" > "+require("util").inspect(b,!0,99,!0)):"debug"===LOGGING&&void 0===b?console.log(a):"alert"===LOGGING&&console.log(a)}; | |
// expose. | |
exports.launch = launch; | |
exports.run = run; | |
function launch(app, action) { | |
_log('*' + app); | |
// use exec (small resturns) over spawn (large binary resturns), see: http://www.hacksparrow.com/difference-between-spawn-and-exec-of-node-js-child_process.html | |
var child = exec('/etc/init.d/' + app + ' ' + action, | |
function (error, stdout, stderr) { | |
if (error !== null) { | |
console.log('error> ' + error); | |
} | |
if (stderr !== '') { | |
console.log('stderr> ' + stderr); | |
} | |
_log('res> ' + stdout); | |
}); | |
} | |
function run(cmd, cb) { | |
_log('*' + cmd); | |
// use exec (small resturns) over spawn (large binary resturns), see: http://www.hacksparrow.com/difference-between-spawn-and-exec-of-node-js-child_process.html | |
// added cwd option which sets the directory for the exec to start from, am using root for flexibility in config['path'] as option. | |
var child = exec(cmd, { cwd: "/" }, function (error, stdout, stderr) { | |
if (error !== null) { | |
console.log('error '+(cmd)+'> ' + error); | |
} | |
if (stderr !== '') { | |
console.log('stderr '+(cmd)+'> ' + stderr); | |
} | |
_log('res '+(cmd)+'> ' + stdout); | |
cb(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment