export database: fix async logic

This commit is contained in:
Girish Ramakrishnan
2020-08-09 09:30:23 -07:00
parent e85f0a4f52
commit aeee8afc02

View File

@@ -782,11 +782,18 @@ function exportDatabase(addon, callback) {
return iteratorCallback(error);
}
safe.fs.writeFileSync(path.join(paths.ADDON_CONFIG_DIR, `exported-${addon}`), '', 'utf8');
shell.sudo('exportDatabase', [ RMADDONDIR_CMD, addon ], {}, iteratorCallback);
iteratorCallback();
});
}, callback);
}, function (error) {
if (error) return callback(error);
async.series([
(done) => fs.writeFile(path.join(paths.ADDON_CONFIG_DIR, `exported-${addon}`), '', 'utf8', done),
// note: after this point, we are restart safe. it's ok if the box code crashes at this point
(done) => shell.exec(`exportDatabase - remove${addon}`, `docker rm -f ${addon}`, done), // what if db writes something when quitting ...
(done) => shell.sudo(`exportDatabase - removeAddonDir${addon}`, [ RMADDONDIR_CMD, addon ], {}, done) // ready to start afresh
], callback);
});
});
}
@@ -1790,7 +1797,7 @@ function startRedis(existingInfra, callback) {
const redisName = 'redis-' + app.id;
async.series([
shell.exec.bind(null, 'stopRedis', `docker stop ${redisName} || true`),
shell.exec.bind(null, 'stopRedis', `docker stop ${redisName} || true`), // redis will backup as part of signal handling
shell.exec.bind(null, 'removeRedis', `docker rm -f ${redisName} || true`),
setupRedis.bind(null, app, app.manifest.addons.redis) // starts the container
], iteratorCallback);