diff --git a/src/apphealthmonitor.js b/src/apphealthmonitor.js index 3bd361b83..dc0f0a05d 100644 --- a/src/apphealthmonitor.js +++ b/src/apphealthmonitor.js @@ -167,7 +167,7 @@ function processDockerEvents() { // do not send mails for dev apps if ((!app || app.appStoreId !== '') && (now - lastOomMailTime > OOM_MAIL_LIMIT)) { - mailer.unexpectedExit(program, context); // app can be null if it's an addon crash + mailer.oomEvent(program, context); // app can be null if it's an addon crash lastOomMailTime = now; } }); diff --git a/src/mail_templates/oom_event.ejs b/src/mail_templates/oom_event.ejs new file mode 100644 index 000000000..130ca2bfd --- /dev/null +++ b/src/mail_templates/oom_event.ejs @@ -0,0 +1,19 @@ +<%if (format === 'text') { %> + +Dear Cloudron Team, + +Unfortunately <%= program %> on <%= fqdn %> exited unexpectedly! + +Please see some excerpt of the logs below. + +Thank you, +Your Cloudron + +------------------------------------- + +<%- context %> + +<% } else { %> + +<% } %> + diff --git a/src/mailer.js b/src/mailer.js index 637e1684c..cef21cb92 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -15,6 +15,7 @@ exports = module.exports = { unexpectedExit: unexpectedExit, appDied: appDied, + oomEvent: oomEvent, outOfDiskSpace: outOfDiskSpace, backupFailed: backupFailed, @@ -499,6 +500,24 @@ function certificateRenewalError(domain, message) { }); } +function oomEvent(program, context) { + assert.strictEqual(typeof program, 'string'); + assert.strictEqual(typeof context, 'string'); + + getAdminEmails(function (error, adminEmails) { + if (error) return console.log('Error getting admins', error); + + var mailOptions = { + from: mailConfig().from, + to: config.provider() === 'caas' ? 'support@cloudron.io' : adminEmails.concat('support@cloudron.io').join(', '), + subject: util.format('[%s] %s exited unexpectedly', config.fqdn(), program), + text: render('oom_event.ejs', { fqdn: config.fqdn(), program: program, context: context, format: 'text' }) + }; + + sendMails([ mailOptions ]); + }); +} + // this function bypasses the queue intentionally. it is also expected to work without the mailer module initialized // NOTE: crashnotifier should be able to send mail when there is no db function unexpectedExit(program, context) {