From ec8c1cad31483ba26c51d90e99e9981c1bbef7f9 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Tue, 7 Sep 2021 16:06:28 +0800 Subject: [PATCH] update healthcheck.js for changing ssl cert / hostname / port --- dockerfile | 2 +- dockerfile-alpine | 2 +- extra/healthcheck.js | 28 ++++++++++++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/dockerfile b/dockerfile index 678f03d56..3dabf513e 100644 --- a/dockerfile +++ b/dockerfile @@ -24,7 +24,7 @@ RUN npm install --legacy-peer-deps && npm run build && npm prune EXPOSE 3001 VOLUME ["/app/data"] -HEALTHCHECK --interval=60s --timeout=30s --start-period=300s CMD node extra/healthcheck.js +HEALTHCHECK --interval=600s --timeout=130s --start-period=300s CMD node extra/healthcheck.js CMD ["node", "server/server.js"] FROM release AS nightly diff --git a/dockerfile-alpine b/dockerfile-alpine index 8674b9993..1dd6b6b53 100644 --- a/dockerfile-alpine +++ b/dockerfile-alpine @@ -19,7 +19,7 @@ RUN npm install --legacy-peer-deps && npm run build && npm prune EXPOSE 3001 VOLUME ["/app/data"] -HEALTHCHECK --interval=60s --timeout=30s --start-period=300s CMD node extra/healthcheck.js +HEALTHCHECK --interval=600s --timeout=130s --start-period=300s CMD node extra/healthcheck.js CMD ["node", "server/server.js"] FROM release AS nightly diff --git a/extra/healthcheck.js b/extra/healthcheck.js index c0b33b6ec..6dfdb23f0 100644 --- a/extra/healthcheck.js +++ b/extra/healthcheck.js @@ -1,19 +1,31 @@ -let http = require("http"); +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + +let client; + +if (process.env.SSL_KEY && process.env.SSL_CERT) { + client = require("https"); +} else { + client = require("http"); +} + let options = { - host: "localhost", - port: "3001", - timeout: 2000, + host: process.env.HOST || "127.0.0.1", + port: parseInt(process.env.PORT) || 3001, + timeout: 120 * 100, }; -let request = http.request(options, (res) => { - console.log(`STATUS: ${res.statusCode}`); - if (res.statusCode == 200) { + +let request = client.request(options, (res) => { + console.log(`Health Check OK [Res Code: ${res.statusCode}]`); + if (res.statusCode === 200) { process.exit(0); } else { process.exit(1); } }); + request.on("error", function (err) { - console.log("ERROR"); + console.error("Health Check ERROR"); process.exit(1); }); + request.end();