Skip to content

Commit

Permalink
Adds email notifications for server restarts and worker issues
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Mar 8, 2022
1 parent 3aa6331 commit 7449fd7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/helper/email/admin/SERVER_START.txt
@@ -0,0 +1,6 @@
Node server started

Log in to server and grep:

tail -n 100000 logs/app.log | grep "Starting pid"

6 changes: 6 additions & 0 deletions app/helper/email/admin/WORKER_ERROR.txt
@@ -0,0 +1,6 @@
Node worker errored

Log in to server and grep:

tail -n 100000 logs/app.log | grep -B 100 "Worker died unexpectedly"

2 changes: 2 additions & 0 deletions app/helper/email/index.js
Expand Up @@ -63,13 +63,15 @@ var MESSAGES = [
"RECOVERED",
"REVOKED",
"SET_PASSWORD",
"SERVER_START",
"SUBSCRIPTION_DECREASE",
"SYNC_DOWN",
"SYNC_EXCEPTION",
"UPCOMING_RENEWAL",
"UPCOMING_EXPIRY",
"UPDATE_BILLING",
"WARNING_LOW_DISK_SPACE",
"WORKER_ERROR"
];

var globals = {
Expand Down
4 changes: 4 additions & 0 deletions app/index.js
Expand Up @@ -3,6 +3,7 @@ const fs = require("fs-extra");
const config = require("config");
const cluster = require("cluster");
const clfdate = require("helper/clfdate");
const email = require("helper/email");

if (cluster.isMaster) {
const NUMBER_OF_CORES = require("os").cpus().length;
Expand All @@ -16,6 +17,8 @@ if (cluster.isMaster) {
`Starting pid=${process.pid} environment=${config.environment} cache=${config.cache}`
);

email.SERVER_START();

// Write the master process PID so we can signal it
fs.writeFileSync(config.pidfile, process.pid.toString(), "utf-8");

Expand All @@ -40,6 +43,7 @@ if (cluster.isMaster) {
if (worker.exitedAfterDisconnect === false) {
console.log(clfdate(), "Worker died unexpectedly, starting a new one");
cluster.fork();
email.WORKER_ERROR();
// worker processes can have scheduled tasks to publish
// scheduled entries in future – if the worker dies it's
// important the master process instead schedules the task
Expand Down

0 comments on commit 7449fd7

Please sign in to comment.