diff --git a/src/cloudron.js b/src/cloudron.js index 5f334c9ae..748b7197b 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -159,7 +159,7 @@ async function getConfig() { footer: branding.renderFooter(allSettings[settings.FOOTER_KEY] || constants.FOOTER), features: appstore.getFeatures(), profileLocked: allSettings[settings.PROFILE_CONFIG_KEY].lockUserProfiles, - mandatory2FA: allSettings[settings.PROFILE_CONFIG_KEY].mandatory2FA + mandatory2FA: allSettings[settings.PROFILE_CONFIG_KEY].mandatory2FA, }; } diff --git a/src/platform.js b/src/platform.js index c97da571b..f3aaa4c12 100644 --- a/src/platform.js +++ b/src/platform.js @@ -4,8 +4,7 @@ exports = module.exports = { start, stopAllTasks, - // exported for testing - _isReady: false + getStatus }; const apps = require('./apps.js'), @@ -26,10 +25,16 @@ const apps = require('./apps.js'), volumes = require('./volumes.js'), _ = require('underscore'); +let gStatusMessage = 'Initializing'; + +function getStatus() { + return { message: gStatusMessage }; +} + async function start(options) { if (process.env.BOX_ENV === 'test' && !process.env.TEST_CREATE_INFRA) return; - debug('initializing addon infrastructure'); + debug('initializing platform'); let existingInfra = { version: 'none' }; if (fs.existsSync(paths.INFRA_VERSION_FILE)) { @@ -52,11 +57,13 @@ async function start(options) { for (let attempt = 0; attempt < 5; attempt++) { try { if (existingInfra.version !== infra.version) { + gStatusMessage = 'Removing containers for upgrade'; await removeAllContainers(); await createDockerNetwork(); } if (existingInfra.version === 'none') await volumes.mountAll(); // when restoring, mount all volumes await markApps(existingInfra, options); // mark app state before we start addons. this gives the db import logic a chance to mark an app as errored + gStatusMessage = 'Starting services, this can take a while'; await services.startServices(existingInfra); await fs.promises.writeFile(paths.INFRA_VERSION_FILE, JSON.stringify(infra, null, 4)); break; @@ -81,7 +88,7 @@ async function stopAllTasks() { async function onPlatformReady(infraChanged) { debug(`onPlatformReady: platform is ready. infra changed: ${infraChanged}`); - exports._isReady = true; + gStatusMessage = 'Ready'; if (infraChanged) await safe(pruneInfraImages(), { debug }); // ignore error diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index 8edb8f5b0..4331b7ca3 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -26,7 +26,8 @@ exports = module.exports = { getLanguages, syncExternalLdap, syncDnsRecords, - getSystemGraphs + getSystemGraphs, + getPlatformStatus }; const assert = require('assert'), @@ -40,6 +41,7 @@ const assert = require('assert'), graphs = require('../graphs.js'), HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess, + platform = require('../platform.js'), safe = require('safetydance'), speakeasy = require('speakeasy'), sysinfo = require('../sysinfo.js'), @@ -359,3 +361,7 @@ async function getSystemGraphs(req, res, next) { next(new HttpSuccess(200, result)); } + +async function getPlatformStatus(req, res, next) { + next(new HttpSuccess(200, platform.getStatus())); +} diff --git a/src/routes/test/apps-test.js b/src/routes/test/apps-test.js index 9f76ad428..d58005dcf 100644 --- a/src/routes/test/apps-test.js +++ b/src/routes/test/apps-test.js @@ -199,7 +199,7 @@ function startBox(done) { function (callback) { process.stdout.write('Waiting for platform to be ready...'); async.retry({ times: 500, interval: 1000 }, function (retryCallback) { - if (platform._isReady) return retryCallback(); + if (platform.getStatus().message === '') return retryCallback(); process.stdout.write('.'); retryCallback('Platform not ready yet'); }, function (error) { diff --git a/src/server.js b/src/server.js index b5296b411..2a2abbd0c 100644 --- a/src/server.js +++ b/src/server.js @@ -150,6 +150,7 @@ function initializeExpressSync() { // config route (for dashboard). can return some private configuration unlike status router.get ('/api/v1/config', token, authorizeUser, routes.cloudron.getConfig); + router.get ('/api/v1/platform_status', token, authorizeUser, routes.cloudron.getPlatformStatus); // working off the user behind the provided token router.get ('/api/v1/profile', token, authorizeUser, routes.profile.get);