diff --git a/src/routes/internal.js b/src/routes/internal.js index 3352f06a0..e9f029d76 100644 --- a/src/routes/internal.js +++ b/src/routes/internal.js @@ -4,7 +4,8 @@ exports = module.exports = { backup: backup, - update: update + update: update, + retire: retire }; var cloudron = require('../cloudron.js'), @@ -39,3 +40,15 @@ function update(req, res, next) { }); } +function retire(req, res, next) { + debug('triggering retire'); + + // note that cloudron.backup only waits for backup initiation and not for backup to complete + // backup progress can be checked up ny polling the progress api call + cloudron.retire(function (error) { + if (error && error.reason === CloudronError.BAD_STATE) return next(new HttpError(409, error.message)); + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(202, {})); + }); +} diff --git a/src/server.js b/src/server.js index 08854c447..23676c62b 100644 --- a/src/server.js +++ b/src/server.js @@ -227,6 +227,7 @@ function initializeInternalExpressSync() { // internal routes router.post('/api/v1/backup', routes.internal.backup); router.post('/api/v1/update', routes.internal.update); + router.post('/api/v1/retire', routes.internal.retire); return httpServer; }