From f37ff53bb6f3fbb0040e4122369159ab348143d9 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Fri, 6 Jan 2023 21:19:57 -0500 Subject: [PATCH] Add way to exit script --- functions.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/functions.js b/functions.js index 5361ef1..8c97de9 100644 --- a/functions.js +++ b/functions.js @@ -14,7 +14,7 @@ config.timestamps.procStart = Date.now(); const dotenv = require('dotenv').config(); // Module for working with files const fs = require('fs'); -const { time } = require('console'); +const { exec } = require('child_process'); const main = (gpio) => { functions.commands.refreshConfig().then(res => { @@ -170,6 +170,16 @@ const functions = { }); }) + }, + quit() { + functions.commands.shutdown(); + functions.auger.off(gpio).then(res => { + console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] I: Exiting app...`); + process.exit(0); + }).catch(err => { + console.log(`[${(Date.now() - config.timestamps.procStart)/1000}] E: Unable to shut off auger, rebooting Pi!`); + exec('shutdown -r 0'); + }); } }, // Sleeps for any given milliseconds