2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
2016-01-14 11:13:00 -08:00
|
|
|
backup: backup,
|
2016-01-25 20:21:04 -08:00
|
|
|
update: update,
|
|
|
|
|
retire: retire
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2016-04-15 11:53:53 -07:00
|
|
|
var backups = require('../backups.js'),
|
|
|
|
|
BackupsError = require('../backups.js').BackupsError,
|
|
|
|
|
cloudron = require('../cloudron.js'),
|
2015-09-17 16:35:59 -07:00
|
|
|
CloudronError = require('../cloudron.js').CloudronError,
|
2016-04-15 12:33:54 -07:00
|
|
|
debug = require('debug')('box:routes/sysadmin'),
|
2015-07-20 00:09:47 -07:00
|
|
|
HttpError = require('connect-lastmile').HttpError,
|
|
|
|
|
HttpSuccess = require('connect-lastmile').HttpSuccess;
|
|
|
|
|
|
|
|
|
|
function backup(req, res, next) {
|
2016-01-14 11:13:00 -08:00
|
|
|
debug('triggering backup');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2015-09-17 16:35:59 -07:00
|
|
|
// 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
|
2016-05-01 13:15:30 -07:00
|
|
|
var auditSource = { userId: null, username: 'sysadmin' };
|
|
|
|
|
backups.backup(auditSource, function (error) {
|
2016-04-15 11:53:53 -07:00
|
|
|
if (error && error.reason === BackupsError.BAD_STATE) return next(new HttpError(409, error.message));
|
2015-09-17 16:35:59 -07:00
|
|
|
if (error) return next(new HttpError(500, error));
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2015-09-17 16:35:59 -07:00
|
|
|
next(new HttpSuccess(202, {}));
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
2016-01-14 11:13:00 -08:00
|
|
|
|
|
|
|
|
function update(req, res, next) {
|
|
|
|
|
debug('triggering update');
|
|
|
|
|
|
|
|
|
|
// this only initiates the update, progress can be checked via the progress route
|
2016-05-01 13:15:30 -07:00
|
|
|
var auditSource = { userId: null, username: 'sysadmin' };
|
|
|
|
|
cloudron.updateToLatest(auditSource, function (error) {
|
2016-01-14 11:13:00 -08:00
|
|
|
if (error && error.reason === CloudronError.ALREADY_UPTODATE) return next(new HttpError(422, error.message));
|
|
|
|
|
if (error && error.reason === CloudronError.BAD_STATE) return next(new HttpError(409, error.message));
|
2016-06-20 14:06:58 +02:00
|
|
|
if (error && error.reason === CloudronError.SELF_UPGRADE_NOT_SUPPORTED) return next(new HttpError(412, error.message));
|
2016-01-14 11:13:00 -08:00
|
|
|
if (error) return next(new HttpError(500, error));
|
|
|
|
|
|
|
|
|
|
next(new HttpSuccess(202, {}));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-25 20:21:04 -08:00
|
|
|
function retire(req, res, next) {
|
|
|
|
|
debug('triggering retire');
|
|
|
|
|
|
|
|
|
|
cloudron.retire(function (error) {
|
2016-06-30 15:05:18 +02:00
|
|
|
if (error) console.error('Retire failed.', error);
|
2016-01-25 20:21:04 -08:00
|
|
|
});
|
2016-06-30 15:05:18 +02:00
|
|
|
|
|
|
|
|
next(new HttpSuccess(202, {}));
|
2016-01-25 20:21:04 -08:00
|
|
|
}
|