diff --git a/src/apptask.js b/src/apptask.js index 95c6df11e..0490abfef 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -38,7 +38,6 @@ const apps = require('./apps.js'), shell = require('./shell.js'), superagent = require('superagent'), sysinfo = require('./sysinfo.js'), - util = require('util'), _ = require('underscore'); const COLLECTD_CONFIG_EJS = fs.readFileSync(__dirname + '/collectd/app.ejs', { encoding: 'utf8' }), @@ -46,12 +45,6 @@ const COLLECTD_CONFIG_EJS = fs.readFileSync(__dirname + '/collectd/app.ejs', { e LOGROTATE_CONFIG_EJS = fs.readFileSync(__dirname + '/logrotate.ejs', { encoding: 'utf8' }), CONFIGURE_LOGROTATE_CMD = path.join(__dirname, 'scripts/configurelogrotate.sh'); -function debugApp(app) { - assert.strictEqual(typeof app, 'object'); - - debug(app.fqdn + ' ' + util.format.apply(util, Array.prototype.slice.call(arguments, 1))); -} - function makeTaskError(error, app) { assert.strictEqual(typeof error, 'object'); assert.strictEqual(typeof app, 'object'); @@ -89,7 +82,7 @@ async function createContainer(app) { assert.strictEqual(typeof app, 'object'); assert(!app.containerId); // otherwise, it will trigger volumeFrom - debugApp(app, 'creating container'); + debug('createContainer: creating container'); const container = await docker.createContainer(app); @@ -104,7 +97,7 @@ async function deleteContainers(app, options) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof options, 'object'); - debugApp(app, 'deleting app containers (app, scheduler)'); + debug('deleteContainer: deleting app containers (app, scheduler)'); // remove configs that rely on container id await removeCollectdProfile(app); @@ -204,7 +197,7 @@ async function cleanupLogs(app) { // note that redis container logs are cleaned up by the addon const [error] = await safe(fs.promises.rm(path.join(paths.LOG_DIR, app.id), { force: true, recursive: true })); - if (error) debugApp(app, 'cannot cleanup logs:', error); + if (error) debug('cleanupLogs: cannot cleanup logs:', error); } async function verifyManifest(manifest) { @@ -223,7 +216,7 @@ async function downloadIcon(app) { // nothing to download if we dont have an appStoreId if (!app.appStoreId) return; - debugApp(app, `Downloading icon of ${app.appStoreId}@${app.manifest.version}`); + debug(`downloadIcon: Downloading icon of ${app.appStoreId}@${app.manifest.version}`); const iconUrl = settings.apiServerOrigin() + '/api/v1/apps/' + app.appStoreId + '/versions/' + app.manifest.version + '/icon'; @@ -244,7 +237,7 @@ async function waitForDnsPropagation(app) { assert.strictEqual(typeof app, 'object'); if (!constants.CLOUDRON) { - debugApp(app, 'Skipping dns propagation check for development'); + debug('waitForDnsPropagation: Skipping dns propagation check for development'); return; } @@ -266,7 +259,7 @@ async function moveDataDir(app, targetDir) { const resolvedSourceDir = apps.getDataDir(app, app.dataDir); const resolvedTargetDir = apps.getDataDir(app, targetDir); - debugApp(app, `moveDataDir: migrating data from ${resolvedSourceDir} to ${resolvedTargetDir}`); + debug(`moveDataDir: migrating data from ${resolvedSourceDir} to ${resolvedTargetDir}`); if (resolvedSourceDir === resolvedTargetDir) return; @@ -287,7 +280,7 @@ async function downloadImage(manifest) { } async function startApp(app) { - debugApp(app, 'startApp: starting container'); + debug('startApp: starting container'); if (app.runState === apps.RSTATE_STOPPED) return; @@ -548,7 +541,6 @@ async function update(app, args, progressCallback) { assert.strictEqual(typeof progressCallback, 'function'); const updateConfig = args.updateConfig; - debugApp(app, `Updating to ${updateConfig.manifest.version}`); // app does not want these addons anymore // FIXME: this does not handle option changes (like multipleDatabases) @@ -597,7 +589,7 @@ async function update(app, args, progressCallback) { if (newTcpPorts[portName] || newUdpPorts[portName]) continue; // port still in use const [error] = await safe(apps.delPortBinding(currentPorts[portName], apps.PORT_TYPE_TCP)); - if (error && error.reason === BoxError.NOT_FOUND) debugApp(app, 'update: portbinding does not exist in database', error); + if (error && error.reason === BoxError.NOT_FOUND) debug('update: portbinding does not exist in database', error); else if (error) throw error; // also delete from app object for further processing (the db is updated in the next step) @@ -715,7 +707,7 @@ async function run(appId, args, progressCallback) { const app = await apps.get(appId); - debugApp(app, `startTask installationState: ${app.installationState} runState: ${app.runState}`); + debug(`run: startTask installationState: ${app.installationState} runState: ${app.runState}`); let cmd; @@ -762,19 +754,19 @@ async function run(appId, args, progressCallback) { cmd = updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null }); break; default: - debugApp(app, 'apptask launched with invalid command'); + debug('run: apptask launched with invalid command'); throw new BoxError(BoxError.INTERNAL_ERROR, 'Unknown install command in apptask:' + app.installationState); } const [error] = await safe(cmd); if (error) { - debugApp(app, `app error for state ${app.installationState}:`, error); + debug(`run: app error for state ${app.installationState}:`, error); if (app.installationState === apps.ISTATE_PENDING_BACKUP) { // return to installed state intentionally. the error is stashed only in the task and not the app (the UI shows error state otherwise) await safe(updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null }), { debug }); } else if (app.installationState === apps.ISTATE_PENDING_UPDATE && error.backupError) { - debugApp(app, 'update aborted because backup failed'); + debug('run: update aborted because backup failed'); await safe(updateApp(app, { installationState: apps.ISTATE_INSTALLED, error: null, health: null }, { debug })); } else { await safe(updateApp(app, { installationState: apps.ISTATE_ERROR, error: makeTaskError(error, app) }), { debug });