Skip to content
Permalink
Browse files

Added daily check for available disk space

  • Loading branch information...
davidmerfield committed Mar 13, 2019
1 parent b840d4e commit 63ffa64647fb3863c5d2c3eb37e0b1c11c181818
Showing with 50 additions and 1 deletion.
  1. +5 −0 app/helper/email/admin/WARNING_LOW_DISK_SPACE.txt
  2. +2 −1 app/helper/email/index.js
  3. +43 −0 app/scheduler.js
@@ -0,0 +1,5 @@
Warning: running out of space on Blot's disk

The storage drive attached to Blot's server is running out of space. It is currently {{usage}} full with {{available}} remaining. Please follow the guide here to resize it:

https://github.com/davidmerfield/Blot/blob/master/config/guides/resize-instance.txt
@@ -53,7 +53,8 @@ var MESSAGES = [
"SYNC_EXCEPTION",
"UPCOMING_RENEWAL",
"UPCOMING_EXPIRY",
"UPDATE_BILLING"
"UPDATE_BILLING",
"WARNING_LOW_DISK_SPACE"
];

var NO_MESSAGE = "No messages found for";
@@ -6,6 +6,8 @@ var schedule = require("node-schedule").scheduleJob;
var Blog = require("./models/blog");
var backup = require("./backup");
var dailyUpdate = require("../scripts/info/dailyUpdate");
var helper = require("helper");
var email = helper.email;

module.exports = function() {
// Bash the cache for scheduled posts
@@ -24,6 +26,47 @@ module.exports = function() {
});
});

console.log("Scheduled daily check of storage disk usage for 6am!");
schedule({ hour: 10, minute: 0 }, function() {
console.log("Scheduler: Checking available disk space");

require("child_process").exec("df -h", function(err, stdout) {
if (err) throw err;

var disk = stdout
.split("\n")[1]
.replace(/\s+/g, " ")
.split(" ");
var usage = disk[4];
var available = disk[3];

if (parseInt(usage) < 90) {
console.log(
"Scheduler: Disk usage check passed! Usage:",
usage,
"Space available:",
available
);
return;
}

console.log(
"Scheduler: Disk usage check failed! Usage:",
usage,
"Space available:",
available
);

email.WARNING_LOW_DISK_SPACE(
null,
{ usage: usage, available: available },
function(err) {
if (err) console.log(err);
}
);
});
});

console.log("Scheduled daily backups for 3am!");
schedule({ hour: 11, minute: 0 }, function() {
// Start the backup daemon

0 comments on commit 63ffa64

Please sign in to comment.
You can’t perform that action at this time.