From 9a08aa2ab5b001ce0be493565646e9fa4c871690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D1=88=D0=BA=D0=B0724=D0=B0=D1=8F?= Date: Sat, 11 Mar 2023 20:57:16 +1100 Subject: [PATCH] Fix healthcheck and some messages --- docker_healthcheck.js | 19 ++++++++++++++----- src/www | 13 ++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docker_healthcheck.js b/docker_healthcheck.js index eeceea584..7c8258ba6 100755 --- a/docker_healthcheck.js +++ b/docker_healthcheck.js @@ -10,18 +10,27 @@ if (config.https) { const port = require('./src/services/port'); const host = require('./src/services/host'); -const url = `http://${host}:${port}/api/health-check`; -const options = { timeout: 2000 }; -const request = http.request(url, options, res => { + +let options = {timeout: 2000}; +const callback = res => { console.log(`STATUS: ${res.statusCode}`); if (res.statusCode === 200) { process.exit(0); } else { process.exit(1); } -}); +}; +let request; +if (port !== 0) { // TCP socket. + const url = `http://${host}:${port}/api/health-check`; + request = http.request(url, options, callback); +} else { // Unix socket. + options.socketPath = host; + options.path = '/api/health-check'; + request = http.request(options, callback); +} request.on("error", err => { console.log("ERROR"); process.exit(1); }); -request.end(); \ No newline at end of file +request.end(); diff --git a/src/www b/src/www index 16989404b..1bf484520 100644 --- a/src/www +++ b/src/www @@ -100,13 +100,14 @@ async function startTrilium() { */ httpServer.keepAliveTimeout = 120000 * 5; - if (port !== 0) { + const listenTcp = port !== 0; + if (listenTcp) { httpServer.listen(port, host); // TCP socket. } else { httpServer.listen(host); // Unix socket. } httpServer.on('error', error => { - if (error.syscall !== 'listen') { + if (!listenTcp || error.syscall !== 'listen') { throw error; } @@ -128,7 +129,13 @@ async function startTrilium() { } ) - httpServer.on('listening', () => log.info(`Listening on port ${httpServer.address().port}`)); + httpServer.on('listening', () => { + if (listenTcp) { + log.info(`Listening on port ${port}`) + } else { + log.info(`Listening on unix socket ${host}`) + } + }); ws.init(httpServer, sessionParser);