From aad330b04c5cc76201e06ca78b56d3f17fc0c6f7 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 10 Apr 2015 20:00:46 -0700 Subject: [PATCH] Wrap execFile --- src/addons.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/addons.js b/src/addons.js index a47e4c936..291774f93 100644 --- a/src/addons.js +++ b/src/addons.js @@ -9,7 +9,6 @@ var appdb = require('./appdb.js'), DatabaseError = require('./databaseerror.js'), debug = require('debug')('box:addons'), docker = require('./docker.js'), - execFile = child_process.execFile, fs = require('fs'), generatePassword = require('password-generator'), MemoryStream = require('memorystream'), @@ -80,6 +79,25 @@ var KNOWN_ADDONS = { var SUDO = '/usr/bin/sudo', RMAPPDIR_CMD = path.join(__dirname, 'scripts/rmappdir.sh'); +function execFile(tag, file, args, callback) { + assert(typeof tag === 'string'); + assert(typeof file === 'string'); + assert(util.isArray(args)); + assert(typeof callback === 'function'); + + var options = { timeout: 0, encoding: 'utf8' }; + + child_process.execFile(file, args, options, function (error, stdout, stderr) { + debug(tag + ' execFile: %s %s', file, args.join(' ')); + debug(tag + ' (stdout): %s', stdout.toString('utf8')); + debug(tag + ' (stderr): %s', stderr.toString('utf8')); + + if (error) debug(tag + ' code: %s, signal: %s', error.code, error.signal); + + callback(error); + }); +} + function setupAddons(app, callback) { assert(typeof app === 'object'); assert(!app.manifest.addons || util.isArray(app.manifest.addons)); @@ -665,7 +683,7 @@ function teardownRedis(app, callback) { safe.fs.unlinkSync(paths.ADDON_CONFIG_DIR, 'redis-' + app.id + '_vars.sh'); - execFile(SUDO, [ RMAPPDIR_CMD, app.id + '/redis' ], { }, function (error, stdout, stderr) { + execFile('teardownRedis', SUDO, [ RMAPPDIR_CMD, app.id + '/redis' ], function (error, stdout, stderr) { if (error) return callback(new Error('Error removing redis data:' + error)); appdb.unsetAddonConfig(app.id, 'redis', callback);