Created
February 27, 2014 16:04
-
-
Save hillar/9253047 to your computer and use it in GitHub Desktop.
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
var LOG_LEVEL = 7; // 7 debug; 6 info; 5 notice; 4 error; | |
var ADMIN = "admin@localhost"; | |
var NodeSyslogLoggerSimple = require('node-syslog-logger-simple'); | |
var logger = new NodeSyslogLoggerSimple({'level':LOG_LEVEL}); | |
logger.debug('logger=ok'); | |
var exec = require('child_process').exec; | |
var EXEC_OPTIONS = { encoding: 'utf8', | |
timeout: 5000, | |
maxBuffer: 200*1024, | |
killSignal: 'SIGTERM', | |
cwd: null, | |
env: null } | |
function doExec(cmd,msg,callback) { | |
var _msg = msg || ""; | |
logger.debug("cmd="+cmd); | |
return exec(cmd, EXEC_OPTIONS, function (error, stdout, stderr) { | |
if ( error ) { | |
logger.error("cmd=\""+cmd+"\"; code="+error.code+"; stderr=\""+stderr+"\";"); | |
return callback(null,"% sorry, something went wrong, please contact "+ADMIN); // no seppuku | |
} | |
if ( stdout ) { | |
logger.debug("stdout="+stdout); | |
return callback(null, _msg +"\n"+stdout); | |
} else { | |
logger.debug("stdout empty!"); | |
return callback(null, "%"); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment