From c93bda5316966d4c4128e4a6a9c8a947e1512fe1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 15 Feb 2024 23:42:27 -0600 Subject: [PATCH] wip --- shell/init_shell.sh | 11 +++++++++-- shell/watcher.js | 37 +++++++++++++++++++++++++++++++++++-- shell/watcher_run_loop.sh | 16 +++++++++++++--- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/shell/init_shell.sh b/shell/init_shell.sh index f62f57a..a16d3f0 100644 --- a/shell/init_shell.sh +++ b/shell/init_shell.sh @@ -1,4 +1,11 @@ -bash /data/openpilot/shell/configure_ssh.sh -bash /data/openpilot/shell/set_logo.sh +cd bash /data/openpilot/shell/ + +bash ./configure_ssh.sh +bash ./set_logo.sh + +cd /data/openpilot/logs + +rm -f watcher.log.gz +ls watcher.log && gzip watcher.log screen -dmS "watcher" "bash /data/openpilot/shell/watcher_run_loop.sh" \ No newline at end of file diff --git a/shell/watcher.js b/shell/watcher.js index 1b06e38..ac5ef42 100644 --- a/shell/watcher.js +++ b/shell/watcher.js @@ -192,5 +192,38 @@ const server = http.createServer((req, res) => { }); server.listen(port, hostname, () => { - console.log(`Server running at http://${hostname}:${port}/`); -}); \ No newline at end of file + 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(); diff --git a/shell/watcher_run_loop.sh b/shell/watcher_run_loop.sh index d9f1c5f..2a82fc6 100644 --- a/shell/watcher_run_loop.sh +++ b/shell/watcher_run_loop.sh @@ -3,9 +3,19 @@ cd /data/openpilot/shell while true do -nodejs watcher.js + nodejs watcher.js + -echo crashed, waiting 30 seconds -sleep 30 +# Get free space on /data in GB +free_space=$(df -BG /data | tail -n 1 | awk '{print $4}' | sed 's/G//') + + # Check if free space is less than 10GB + if [ "$free_space" -lt 10 ]; then + echo "Less than 10GB of free space on /data. Exiting." + exit 1 + fi + + echo crashed, waiting 30 seconds + sleep 30 done \ No newline at end of file