From 39a21766b684d348ff604f9f4ce8abc7a5f3258f Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Sat, 14 Oct 2023 20:02:04 +0200 Subject: [PATCH] Exit on start up errors --- lib/www/server/index.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/www/server/index.js b/lib/www/server/index.js index 09221bd..26bf562 100755 --- a/lib/www/server/index.js +++ b/lib/www/server/index.js @@ -8,23 +8,29 @@ async function main () { INFO("Running version", await version.describe()); version.compatible() .then( (versions) => { - const api = require('./api'); - const ws = require('./ws'); + try { + const api = require('./api'); + const ws = require('./ws'); - const { fork } = require('child_process'); + const { fork } = require('child_process'); - const port = process.env.HTTP_PORT || 3000; - const host = process.env.HTTP_HOST || "127.0.0.1"; - const path = process.env.HTTP_PATH ?? "/api"; - const server = api.start(port, host, path); - ws.start(server); + const port = process.env.HTTP_PORT || 3000; + const host = process.env.HTTP_HOST || "127.0.0.1"; + const path = process.env.HTTP_PATH ?? "/api"; + const server = api.start(port, host, path); + ws.start(server); - const eventManagerPath = [__dirname, "events"].join("/"); - const eventManager = fork(eventManagerPath, /*{ stdio: 'ignore' }*/); + INFO("Versions:", versions); - INFO("Versions:", versions); process.on('exit', () => eventManager.kill()); + const eventManagerPath = [__dirname, "events"].join("/"); + const eventManager = fork(eventManagerPath, /*{ stdio: 'ignore' }*/); + + } catch (err) { + ERROR(err); + process.exit(2); + } }) .catch( ({current, wanted, component}) => { console.error(`Fatal error: incompatible ${component} version ${current} (wanted: ${wanted})`);