add route to get platform status
This commit is contained in:
+11
-4
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user