diff --git a/src/apps.js b/src/apps.js index 6fa80d0ff..f64a59bf8 100644 --- a/src/apps.js +++ b/src/apps.js @@ -1186,14 +1186,16 @@ function uninstall(appId, auditSource, callback) { if (error && error.reason === AppstoreError.EXTERNAL_ERROR) return callback(new AppsError(AppsError.EXTERNAL_ERROR, error.message)); if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); - taskmanager.stopAppTask(appId, function () { - appdb.setInstallationCommand(appId, appdb.ISTATE_PENDING_UNINSTALL, function (error) { - if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app')); - if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); + appdb.setInstallationCommand(appId, appdb.ISTATE_PENDING_UNINSTALL, function (error) { + if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND, 'No such app')); + if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error)); - eventlog.add(eventlog.ACTION_APP_UNINSTALL, auditSource, { appId: appId, app: app }); + startAppTask(appId, function (error, result) { + if (error) return callback(error); - taskmanager.startAppTask(appId, callback); + eventlog.add(eventlog.ACTION_APP_UNINSTALL, auditSource, { appId: appId, app: result }); + + callback(null); }); }); }); diff --git a/src/apptask.js b/src/apptask.js index cb6f085b8..32f3ed22f 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -826,53 +826,52 @@ function update(app, callback) { }); } -function uninstall(app, callback) { +function uninstall(app, progressCallback, callback) { assert.strictEqual(typeof app, 'object'); + assert.strictEqual(typeof progressCallback, 'function'); assert.strictEqual(typeof callback, 'function'); - debugApp(app, 'uninstalling'); - async.series([ - updateApp.bind(null, app, { installationProgress: '0, Remove collectd profile' }), + progressCallback.bind(null, { percent: 0, message: 'Remove collectd profile' }), removeCollectdProfile.bind(null, app), - updateApp.bind(null, app, { installationProgress: '5, Remove logrotate config' }), + progressCallback.bind(null, { percent: 5, message: 'Remove logrotate config' }), removeLogrotateConfig.bind(null, app), - updateApp.bind(null, app, { installationProgress: '10, Stopping app' }), + progressCallback.bind(null, { percent: 10, message: 'Stopping app' }), stopApp.bind(null, app), - updateApp.bind(null, app, { installationProgress: '20, Deleting container' }), + progressCallback.bind(null, { percent: 20, message: 'Deleting container' }), deleteContainers.bind(null, app, {}), - updateApp.bind(null, app, { installationProgress: '30, Teardown addons' }), + progressCallback.bind(null, { percent: 30, message: 'Teardown addons' }), addons.teardownAddons.bind(null, app, app.manifest.addons), - updateApp.bind(null, app, { installationProgress: '40, Deleting app data directory' }), + progressCallback.bind(null, { percent: 40, message: 'Deleting app data directory' }), deleteAppDir.bind(null, app, { removeDirectory: true }), - updateApp.bind(null, app, { installationProgress: '50, Deleting image' }), + progressCallback.bind(null, { percent: 50, message: 'Deleting image' }), docker.deleteImage.bind(null, app.manifest), - updateApp.bind(null, app, { installationProgress: '60, Unregistering domains' }), + progressCallback.bind(null, { percent: 60, message: 'Unregistering domains' }), unregisterAlternateDomains.bind(null, app, true /* all */), unregisterSubdomain.bind(null, app, app.location, app.domain), - updateApp.bind(null, app, { installationProgress: '70, Cleanup icon' }), + progressCallback.bind(null, { percent: 70, message: 'Cleanup icon' }), removeIcon.bind(null, app), - updateApp.bind(null, app, { installationProgress: '80, Unconfiguring reverse proxy' }), + progressCallback.bind(null, { percent: 80, message: 'Unconfiguring reverse proxy' }), unconfigureReverseProxy.bind(null, app), - updateApp.bind(null, app, { installationProgress: '90, Cleanup logs' }), + progressCallback.bind(null, { percent: 90, message: 'Cleanup logs' }), cleanupLogs.bind(null, app), - updateApp.bind(null, app, { installationProgress: '95, Remove app from database' }), + progressCallback.bind(null, { percent: 95, message: 'Remove app from database' }), appdb.del.bind(null, app.id) ], function seriesDone(error) { if (error) { debugApp(app, 'error uninstalling app: %s', error); - return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message }, callback.bind(null, error)); + return updateApp(app, { installationState: appdb.ISTATE_ERROR, installationProgress: error.message, taskId: null }, callback.bind(null, error)); } callback(null); }); @@ -966,6 +965,7 @@ function run(appId, progressCallback, callback) { switch (app.installationState) { case appdb.ISTATE_PENDING_INSTALL: return install(app, progressCallback, callback); case appdb.ISTATE_PENDING_CONFIGURE: return configure(app, progressCallback, callback); + case appdb.ISTATE_PENDING_UNINSTALL: return uninstall(app, progressCallback, callback); default: debugApp(app, 'apptask launched with invalid command');