Add backup configuration check together with out of disk check cron job
This commit is contained in:
+33
-5
@@ -18,6 +18,8 @@ exports = module.exports = {
|
||||
setDashboardDomain: setDashboardDomain,
|
||||
renewCerts: renewCerts,
|
||||
|
||||
systemChecks: systemChecks,
|
||||
checkBackupConfiguration: checkBackupConfiguration,
|
||||
checkDiskSpace: checkDiskSpace
|
||||
};
|
||||
|
||||
@@ -35,6 +37,7 @@ var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
mail = require('./mail.js'),
|
||||
mailer = require('./mailer.js'),
|
||||
notifications = require('./notifications.js'),
|
||||
os = require('os'),
|
||||
path = require('path'),
|
||||
paths = require('./paths.js'),
|
||||
@@ -183,8 +186,34 @@ function isRebootRequired(callback) {
|
||||
callback(null, fs.existsSync('/var/run/reboot-required'));
|
||||
}
|
||||
|
||||
// called from cron.js
|
||||
function systemChecks() {
|
||||
async.parallel([
|
||||
checkBackupConfiguration,
|
||||
checkDiskSpace
|
||||
], function () {
|
||||
debug('systemChecks: done');
|
||||
});
|
||||
}
|
||||
|
||||
function checkBackupConfiguration(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debug('Checking backup configuration');
|
||||
|
||||
settings.getBackupConfig(function (error, backupConfig) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
if (backupConfig.provider === 'noop') {
|
||||
notifications.backupConfigWarning('Cloudron backups are disabled. Please ensure this server is backed up using alternate means.');
|
||||
} else if (backupConfig.provider === 'filesystem' && !backupConfig.externalDisk) {
|
||||
notifications.backupConfigWarning('Cloudron backups are currently on the same disk as the Cloudron server instance. This is dangerous and can lead to complete data loss if the disk fails.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkDiskSpace(callback) {
|
||||
callback = callback || NOOP_CALLBACK;
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
debug('Checking disk space');
|
||||
|
||||
@@ -214,13 +243,12 @@ function checkDiskSpace(callback) {
|
||||
|
||||
debug('Disk space checked. ok: %s', !oos);
|
||||
|
||||
if (oos) mailer.outOfDiskSpace(JSON.stringify(entries, null, 4));
|
||||
if (oos) notifications.diskSpaceWarning(JSON.stringify(entries, null, 4));
|
||||
|
||||
callback();
|
||||
}).catch(function (error) {
|
||||
debug('df error %s', error.message);
|
||||
mailer.outOfDiskSpace(error.message);
|
||||
return callback();
|
||||
if (error) console.error(error);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+5
-5
@@ -35,7 +35,7 @@ var gJobs = {
|
||||
backup: null,
|
||||
boxUpdateChecker: null,
|
||||
caasHeartbeat: null,
|
||||
checkDiskSpace: null,
|
||||
systemChecks: null,
|
||||
certificateRenew: null,
|
||||
cleanupBackups: null,
|
||||
cleanupEventlog: null,
|
||||
@@ -115,10 +115,10 @@ function recreateJobs(tz) {
|
||||
timeZone: tz
|
||||
});
|
||||
|
||||
if (gJobs.checkDiskSpace) gJobs.checkDiskSpace.stop();
|
||||
gJobs.checkDiskSpace = new CronJob({
|
||||
cronTime: '00 30 */4 * * *', // every 4 hours
|
||||
onTick: cloudron.checkDiskSpace,
|
||||
if (gJobs.systemChecks) gJobs.systemChecks.stop();
|
||||
gJobs.systemChecks = new CronJob({
|
||||
cronTime: '00 30 * * * *', // every hour
|
||||
onTick: cloudron.systemChecks,
|
||||
start: true,
|
||||
timeZone: tz
|
||||
});
|
||||
|
||||
+3
-2
@@ -440,7 +440,8 @@ function sendDigest(info) {
|
||||
});
|
||||
}
|
||||
|
||||
function outOfDiskSpace(message) {
|
||||
function outOfDiskSpace(mailTo, message) {
|
||||
assert.strictEqual(typeof mailTo, 'string');
|
||||
assert.strictEqual(typeof message, 'string');
|
||||
|
||||
getMailConfig(function (error, mailConfig) {
|
||||
@@ -448,7 +449,7 @@ function outOfDiskSpace(message) {
|
||||
|
||||
var mailOptions = {
|
||||
from: mailConfig.notificationFrom,
|
||||
to: config.provider() === 'caas' ? 'support@cloudron.io' : mailConfig.adminEmails.join(', '),
|
||||
to: mailTo,
|
||||
subject: util.format('[%s] Out of disk space alert', mailConfig.cloudronName),
|
||||
text: render('out_of_disk_space.ejs', { cloudronName: mailConfig.cloudronName, message: message, format: 'text' })
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user