diff --git a/src/apphealthmonitor.js b/src/apphealthmonitor.js index 4f8fc8989..7ccb7cacf 100644 --- a/src/apphealthmonitor.js +++ b/src/apphealthmonitor.js @@ -95,8 +95,10 @@ async function checkAppHealth(app, options) { .timeout(options.timeout * 1000)); if (healthCheckError) { + await apps.appendLogLine(app, `=> Healtheck error: ${healthCheckError}`); await setHealth(app, apps.HEALTH_UNHEALTHY); } else if (response.status > 403) { // 2xx and 3xx are ok. even 401 and 403 are ok for now (for WP sites) + await apps.appendLogLine(app, `=> Healtheck error got response status ${response.status}`); await setHealth(app, apps.HEALTH_UNHEALTHY); } else { await setHealth(app, apps.HEALTH_HEALTHY); diff --git a/src/apps.js b/src/apps.js index 7aff191bc..8dc0f63d2 100644 --- a/src/apps.js +++ b/src/apps.js @@ -61,6 +61,8 @@ exports = module.exports = { getLogPaths, getLogs, + appendLogLine, + getCertificate, start, @@ -2013,6 +2015,16 @@ async function getLogs(app, options) { return transformStream; } +// never fails just prints error +async function appendLogLine(app, line) { + assert.strictEqual(typeof app, 'object'); + assert.strictEqual(typeof line, 'string'); + + const logFilePath = path.join(paths.LOG_DIR, app.id, 'app.log'); + + if (!safe.fs.appendFileSync(logFilePath, line)) console.error(`Could not append log line for app ${app.id} at ${logFilePath}: ${safe.error.message}`); +} + async function getCertificate(subdomain, domain) { assert.strictEqual(typeof subdomain, 'string'); assert.strictEqual(typeof domain, 'string');