platform.js: minor refactor

This commit is contained in:
Girish Ramakrishnan
2016-05-24 10:58:18 -07:00
parent e5a030baff
commit 5ac1d5575c
+19 -10
View File
@@ -5,6 +5,7 @@ exports = module.exports = {
};
var apps = require('./apps.js'),
assert = require('assert'),
config = require('./config.js'),
certificates = require('./certificates.js'),
debug = require('debug')('box:platform'),
@@ -39,21 +40,17 @@ function initialize(callback) {
if (!existingInfra.INFRA_VERSION) removeImagesSync(); // a hack for --recreate-infra
certificates.getAdminCertificatePath(function (error, certFilePath, keyFilePath) {
startAddons(function (error) {
if (error) return callback(error);
shell.sudo('seutp_infra', [ SETUP_INFRA_CMD, paths.DATA_DIR, config.fqdn(), config.adminFqdn(), certFilePath, keyFilePath ], function (error) {
var func = existingInfra ? apps.configureInstalledApps : apps.restoreInstalledApps;
func(function (error) {
if (error) return callback(error);
var func = existingInfra ? apps.configureInstalledApps : apps.restoreInstalledApps;
fs.writeFileSync(paths.INFRA_VERSION_FILE, currentInfraData);
func(function (error) {
if (error) return callback(error);
fs.writeFileSync(paths.INFRA_VERSION_FILE, currentInfraData);
callback();
});
callback();
});
});
}
@@ -68,3 +65,15 @@ function stopContainersSync() {
debug('stopping existing containers');
shell.execSync('stopContainersSync', 'docker ps -qa | xargs --no-run-if-empty docker rm -f');
}
function startAddons(callback) {
assert.strictEqual(typeof callback, 'function');
certificates.getAdminCertificatePath(function (error, certFilePath, keyFilePath) {
if (error) return callback(error);
shell.sudo('seutp_infra', [ SETUP_INFRA_CMD, paths.DATA_DIR, config.fqdn(), config.adminFqdn(), certFilePath, keyFilePath ], function (error) {
callback(error);
});
});
}