diff --git a/src/apps.js b/src/apps.js index f2e181495..750516284 100644 --- a/src/apps.js +++ b/src/apps.js @@ -2354,8 +2354,9 @@ async function listBackups(app, page, perPage) { return await backups.getByIdentifierAndStatePaged(app.id, backups.BACKUP_STATE_NORMAL, page, perPage); } -async function restoreInstalledApps(options) { +async function restoreInstalledApps(options, auditSource) { assert.strictEqual(typeof options, 'object'); + assert.strictEqual(typeof auditSource, 'object'); let apps = await list(); apps = apps.filter(app => app.installationState !== exports.ISTATE_ERROR); // remove errored apps. let them be 'repaired' by hand @@ -2389,7 +2390,9 @@ async function restoreInstalledApps(options) { } } -async function configureInstalledApps() { +async function configureInstalledApps(auditSource) { + assert.strictEqual(typeof auditSource, 'object'); + let apps = await list(); apps = apps.filter(app => app.installationState !== exports.ISTATE_ERROR); // remove errored apps. let them be 'repaired' by hand apps = apps.filter(app => app.installationState !== exports.ISTATE_PENDING_CONFIGURE); // safeguard against tasks being created non-stop if we crash on startup @@ -2410,8 +2413,9 @@ async function configureInstalledApps() { } } -async function restartAppsUsingAddons(changedAddons) { +async function restartAppsUsingAddons(changedAddons, auditSource) { assert(Array.isArray(changedAddons)); + assert.strictEqual(typeof auditSource, 'object'); let apps = await list(); apps = apps.filter(app => app.manifest.addons && _.intersection(Object.keys(app.manifest.addons), changedAddons).length !== 0); @@ -2438,7 +2442,9 @@ async function restartAppsUsingAddons(changedAddons) { } // auto-restart app tasks after a crash -async function schedulePendingTasks() { +async function schedulePendingTasks(auditSource) { + assert.strictEqual(typeof auditSource, 'object'); + debug('schedulePendingTasks: scheduling app tasks'); const result = await list(); diff --git a/src/auditsource.js b/src/auditsource.js index f834cd7b5..d54d6d9f9 100644 --- a/src/auditsource.js +++ b/src/auditsource.js @@ -19,5 +19,6 @@ AuditSource.HEALTH_MONITOR = new AuditSource('healthmonitor'); AuditSource.EXTERNAL_LDAP_TASK = new AuditSource('externalldap'); AuditSource.EXTERNAL_LDAP_AUTO_CREATE = new AuditSource('externalldap'); AuditSource.APPTASK = new AuditSource('apptask'); +AuditSource.PLATFORM = new AuditSource('platform'); exports = module.exports = AuditSource; diff --git a/src/platform.js b/src/platform.js index f9f371740..8775e42e3 100644 --- a/src/platform.js +++ b/src/platform.js @@ -10,6 +10,7 @@ exports = module.exports = { const apps = require('./apps.js'), assert = require('assert'), + AuditSource = require('./auditsource.js'), BoxError = require('./boxerror.js'), debug = require('debug')('box:platform'), delay = require('delay'), @@ -81,7 +82,7 @@ async function onPlatformReady(infraChanged) { if (infraChanged) await safe(pruneInfraImages(), { debug }); // ignore error - await apps.schedulePendingTasks(); + await apps.schedulePendingTasks(AuditSource.PLATFORM); } async function pruneInfraImages() { @@ -123,11 +124,11 @@ async function markApps(existingInfra, options) { if (existingInfra.version === 'none') { // cloudron is being restored from backup debug('markApps: restoring installed apps'); - await apps.restoreInstalledApps(options); + await apps.restoreInstalledApps(options, AuditSource.PLATFORM); } else if (existingInfra.version !== infra.version) { debug('markApps: reconfiguring installed apps'); reverseProxy.removeAppConfigs(); // should we change the cert location, nginx will not start - await apps.configureInstalledApps(); + await apps.configureInstalledApps(AuditSource.PLATFORM); } else { let changedAddons = []; if (infra.images.mysql.tag !== existingInfra.images.mysql.tag) changedAddons.push('mysql'); @@ -138,7 +139,7 @@ async function markApps(existingInfra, options) { if (changedAddons.length) { // restart apps if docker image changes since the IP changes and any "persistent" connections fail debug(`markApps: changedAddons: ${JSON.stringify(changedAddons)}`); - await apps.restartAppsUsingAddons(changedAddons); + await apps.restartAppsUsingAddons(changedAddons, AuditSource.PLATFORM); } else { debug('markApps: apps are already uptodate'); }