wip
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user