diff --git a/src/apps.js b/src/apps.js index c5d733b29..ff09f57f2 100644 --- a/src/apps.js +++ b/src/apps.js @@ -634,7 +634,6 @@ function scheduleTask(appId, args, values, callback) { tasks.add(tasks.TASK_APP, [ appId, args ], function (error, taskId) { if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); - values.error = null; values.taskId = taskId; appdb.setTask(appId, values, function (error) { @@ -1758,6 +1757,7 @@ function restoreInstalledApps(callback) { getAll(function (error, apps) { if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + apps = apps.filter(app => app.installationState !== exports.ISTATE_ERROR); // remove errored apps. let them be 'repaired' by hand async.map(apps, function (app, iteratorDone) { backups.getByAppIdPaged(1, 1, app.id, function (error, results) { @@ -1765,7 +1765,7 @@ function restoreInstalledApps(callback) { debug(`marking ${app.fqdn} for restore using restore config ${JSON.stringify(restoreConfig)}`); - appdb.update(app.id, { taskId: null }, function (error) { // clear any stale taskId + appdb.update(app.id, { taskId: null, error: null }, function (error) { // clear any stale taskId if (error) debug(`Error marking ${app.fqdn} for restore: ${JSON.stringify(error)}`); scheduleTask(app.id, { restoreConfig, overwriteDns: true }, { installationState: exports.ISTATE_PENDING_RESTORE }, () => iteratorDone()); // always succeed @@ -1780,14 +1780,16 @@ function configureInstalledApps(callback) { getAll(function (error, apps) { if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + apps = apps.filter(app => app.installationState !== exports.ISTATE_ERROR); // remove errored apps. let them be 'repaired' by hand async.map(apps, function (app, iteratorDone) { debug(`marking ${app.fqdn} for reconfigure`); - appdb.update(app.id, { taskId: null }, function (error) { // clear any stale taskId + appdb.update(app.id, { taskId: null, error: null }, function (error) { // clear any stale taskId if (error) debug(`Error marking ${app.fqdn} for reconfigure: ${JSON.stringify(error)}`); - scheduleTask(app.id, { oldConfig: app }, { installationState: exports.ISTATE_PENDING_CONFIGURE }, () => iteratorDone()); // always succeed + const oldConfig = _.pick(app, 'location', 'domain', 'fqdn', 'alternateDomains', 'portBindings'); + scheduleTask(app.id, { oldConfig }, { installationState: exports.ISTATE_PENDING_CONFIGURE }, () => iteratorDone()); // always succeed }); }, callback); }); diff --git a/src/test/apps-test.js b/src/test/apps-test.js index 5cc969000..c89916415 100644 --- a/src/test/apps-test.js +++ b/src/test/apps-test.js @@ -378,7 +378,7 @@ describe('Apps', function () { apps.getAll(function (error, result) { expect(result[0].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE); - expect(result[1].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE); // erorred app can be reconfigured after restore + expect(result[1].installationState).to.be(apps.ISTATE_ERROR); expect(result[2].installationState).to.be(apps.ISTATE_PENDING_CONFIGURE); done(); @@ -402,7 +402,7 @@ describe('Apps', function () { apps.getAll(function (error, result) { expect(result[0].installationState).to.be(apps.ISTATE_PENDING_RESTORE); - expect(result[1].installationState).to.be(apps.ISTATE_PENDING_RESTORE); + expect(result[1].installationState).to.be(apps.ISTATE_ERROR); expect(result[2].installationState).to.be(apps.ISTATE_PENDING_RESTORE); done();