diff --git a/src/eventlog.js b/src/eventlog.js index fce384797..c963af143 100644 --- a/src/eventlog.js +++ b/src/eventlog.js @@ -113,6 +113,8 @@ function add(action, source, data, callback) { notifications.oomEvent(id, source.app ? source.app.id : source.containerId, { app: source.app, details: data }); } if (action === exports.ACTION_APP_DOWN) { notifications.appDied(id, source.app); + } if (action === exports.ACTION_APP_TASK_CRASH) { + notifications.apptaskCrash(id, source.appId, data.crashLogFile); } if (action === exports.ACTION_PROCESS_CRASH) { notifications.unexpectedExit(id, source.processName, data.crashLogFile); } else { diff --git a/src/notifications.js b/src/notifications.js index 0e1f3c51b..d13ecaeb8 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -14,7 +14,8 @@ exports = module.exports = { adminChanged: adminChanged, oomEvent: oomEvent, appDied: appDied, - unexpectedExit: unexpectedExit + unexpectedExit: unexpectedExit, + apptaskCrash: apptaskCrash }; var assert = require('assert'), @@ -226,3 +227,22 @@ function unexpectedExit(eventId, processName, crashLogFile) { if (error) console.error(error); }); } + +function apptaskCrash(eventId, appId, crashLogFile) { + assert.strictEqual(typeof eventId, 'string'); + assert.strictEqual(typeof appId, 'string'); + assert.strictEqual(typeof crashLogFile, 'string'); + + var subject = `Apptask for ${appId} crashed`; + var crashLogs = safe.fs.readFileSync(crashLogFile, 'utf8'); + + // also send us a notification mail + if (config.provider() === 'caas') mailer.unexpectedExit('support@cloudron.io', subject, crashLogs); + + actionForAllAdmins([], function (admin, callback) { + mailer.unexpectedExit(admin.email, subject, crashLogs); + add(admin.id, eventId, subject, 'Detailed logs have been sent to your email address.', '/#/system', callback); + }, function (error) { + if (error) console.error(error); + }); +}