This commit is contained in:
Your Name
2024-02-15 23:42:27 -06:00
parent 8c60f0956b
commit c93bda5316
3 changed files with 57 additions and 7 deletions

View File

@@ -192,5 +192,38 @@ const server = http.createServer((req, res) => {
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
console.log(`Web Server running at http://${hostname}:${port}/`);
});
//// Exit when low disk space /////
const { exec } = require('child_process');
// Function to check disk space
function checkDiskSpace() {
exec('df -BG /data | tail -n 1 | awk \'{print $4}\'', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
// Extract the number of GBs available
const freeSpaceGB = parseInt(stdout.trim().replace('G', ''));
// Check if free space is less than 10GB
if (freeSpaceGB < 9) {
console.log('Less than 9GB of free space on /data. Exiting.');
process.exit(1);
}
});
}
// Check disk space every 1 minute
setInterval(checkDiskSpace, 60000);
// Perform an initial check
checkDiskSpace();