diff --git a/src/cloudron.js b/src/cloudron.js index 461fa3a62..3d09cdc1b 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -183,19 +183,16 @@ function getConfig(callback) { }); } -function reboot(callback) { - notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', '', function (error) { - if (error) debug('reboot: failed to clear reboot notification.', error); +async function reboot() { + await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', ''); - shell.sudo('reboot', [ REBOOT_CMD ], {}, callback); - }); + const [error] = await safe(shell.promises.sudo('reboot', [ REBOOT_CMD ], {})); + if (error) debug('reboot: could not reboot', error); } -function isRebootRequired(callback) { - assert.strictEqual(typeof callback, 'function'); - +async function isRebootRequired() { // https://serverfault.com/questions/92932/how-does-ubuntu-keep-track-of-the-system-restart-required-flag-in-motd - callback(null, fs.existsSync('/var/run/reboot-required')); + return fs.existsSync('/var/run/reboot-required'); } // called from cron.js @@ -214,30 +211,24 @@ function runSystemChecks(callback) { function checkMailStatus(callback) { assert.strictEqual(typeof callback, 'function'); - mail.checkConfiguration(function (error, message) { + mail.checkConfiguration(async function (error, message) { if (error) return callback(error); - notifications.alert(notifications.ALERT_MAIL_STATUS, 'Email is not configured properly', message, callback); + await safe(notifications.alert(notifications.ALERT_MAIL_STATUS, 'Email is not configured properly', message)); + callback(); }); } -function checkRebootRequired(callback) { - assert.strictEqual(typeof callback, 'function'); - - isRebootRequired(function (error, rebootRequired) { - if (error) return callback(error); - - notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', rebootRequired ? 'To finish ubuntu security updates, a reboot is necessary.' : '', callback); - }); +async function checkRebootRequired() { + const rebootRequired = await isRebootRequired(); + await notifications.alert(notifications.ALERT_REBOOT, 'Reboot Required', rebootRequired ? 'To finish ubuntu security updates, a reboot is necessary.' : ''); } -function checkUbuntuVersion(callback) { - assert.strictEqual(typeof callback, 'function'); - +async function checkUbuntuVersion() { const isXenial = fs.readFileSync('/etc/lsb-release', 'utf-8').includes('16.04'); - if (!isXenial) return callback(); + if (!isXenial) return; - notifications.alert(notifications.ALERT_UPDATE_UBUNTU, 'Ubuntu upgrade required', 'Ubuntu 16.04 has reached end of life and will not receive security and maintenance updates. Please follow https://docs.cloudron.io/guides/upgrade-ubuntu-18/ to upgrade to Ubuntu 18 at the earliest.', callback); + await notifications.alert(notifications.ALERT_UPDATE_UBUNTU, 'Ubuntu upgrade required', 'Ubuntu 16.04 has reached end of life and will not receive security and maintenance updates. Please follow https://docs.cloudron.io/guides/upgrade-ubuntu-18/ to upgrade to Ubuntu 18 at the earliest.'); } function getLogs(unit, options, callback) { diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index f9c13a2f0..624c5f278 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -137,19 +137,18 @@ function setupAccount(req, res, next) { }); } -function reboot(req, res, next) { +async function reboot(req, res, next) { // Finish the request, to let the appstore know we triggered the reboot next(new HttpSuccess(202, {})); - cloudron.reboot(function () {}); + await safe(cloudron.reboot()); } -function isRebootRequired(req, res, next) { - cloudron.isRebootRequired(function (error, result) { - if (error) return next(BoxError.toHttpError(error)); +async function isRebootRequired(req, res, next) { + const [error, rebootRequired] = await safe(cloudron.isRebootRequired()); + if (error) return next(BoxError.toHttpError(error)); - next(new HttpSuccess(200, { rebootRequired: result })); - }); + next(new HttpSuccess(200, { rebootRequired })); } function getConfig(req, res, next) {