diff --git a/src/apphealthmonitor.js b/src/apphealthmonitor.js index 0122087f8..53626a525 100644 --- a/src/apphealthmonitor.js +++ b/src/apphealthmonitor.js @@ -46,7 +46,9 @@ function setHealth(app, health, callback) { debugApp(app, 'marking as unhealthy since not seen for more than %s minutes', UNHEALTHY_THRESHOLD/(60 * 1000)); - if (!app.debugMode) notifications.appDied(app); // do not send mails for dev apps + // do not send mails for dev apps + if (!app.debugMode) eventlog.add(eventlog.ACTION_APP_DOWN, { app: app }, {}); + gHealthInfo[app.id].emailSent = true; } else { debugApp(app, 'waiting for sometime to update the app health'); diff --git a/src/eventlog.js b/src/eventlog.js index 5ab6749de..4ec394e2f 100644 --- a/src/eventlog.js +++ b/src/eventlog.js @@ -19,6 +19,7 @@ exports = module.exports = { ACTION_APP_UPDATE: 'app.update', ACTION_APP_LOGIN: 'app.login', ACTION_APP_OOM: 'app.oom', + ACTION_APP_DOWN: 'app.down', ACTION_BACKUP_FINISH: 'backup.finish', ACTION_BACKUP_START: 'backup.start', @@ -106,7 +107,9 @@ function add(action, source, data, callback) { } if (action === exports.ACTION_USER_UPDATE && data.adminStatusChanged) { notifications.adminChanged(source.userId, data.user); } if (action === exports.ACTION_APP_OOM) { - notifications.oomEvent(source.app ? source.app.id : source.containerId, data); + notifications.oomEvent(source.app ? source.app.id : source.containerId, { app: source.app, details: data }); + } if (action === exports.ACTION_APP_DOWN) { + notifications.appDied(source.app); } else { // no notification } diff --git a/src/notifications.js b/src/notifications.js index b498c3b91..a35b025af 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -189,19 +189,18 @@ function oomEvent(program, context) { }); } -function appDied(app, callback) { +function appDied(app) { assert.strictEqual(typeof app, 'object'); - assert(typeof callback === 'undefined' || typeof callback === 'function'); - - callback = callback || NOOP_CALLBACK; // also send us a notification mail if (config.provider() === 'caas') mailer.appDied('support@cloudron.io', app); actionForAllAdmins([], function (admin, callback) { mailer.appDied(admin.email, app); - add(admin.id, `App ${app.fqdn} died`, `The application ${app.manifest.title} installed at ${app.fqdn} is not responding.`, '/#/apps', callback); - }, callback); + add(admin.id, `App ${app.fqdn} is down`, `The application ${app.manifest.title} installed at ${app.fqdn} is not responding.`, '/#/apps', callback); + }, function (error) { + if (error) console.error(error); + }); } function unexpectedExit(subject, compiledLogs, callback) {