Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
reimplement docker healtcheck into node.js to take into account configuration, #3582
zadam260bc93a6631
diff --git a/DockerHealthcheck.sh b/DockerHealthcheck.shdeleted file mode 100755index 0efe4b2d48..0000000000--- a/DockerHealthcheck.sh+++ /dev/null@@ -1,13 +0,0 @@-#!/bin/sh--# Try connecting to /api/health-check using both http and https.-# TODO: we should only be connecting with the actual protocol that is enabled-# TODO: this assumes we use the default port 8080--for proto in http https; do- if wget --spider -S "$proto://127.0.0.1:8080/api/health-check" 2>&1 | awk 'NR==2' | grep -w "HTTP/1.1 200 OK" ; then- exit 0- fi-done--exit 1diff --git a/Dockerfile b/Dockerfileindex 60fc5f5402..a100b9ccbe 100644--- a/Dockerfile+++ b/Dockerfile@@ -39,4 +39,4 @@ RUN adduser -s /bin/false node; exit 0EXPOSE 8080CMD [ "./start-docker.sh" ]-HEALTHCHECK CMD sh DockerHealthcheck.sh+HEALTHCHECK CMD node docker_healthcheck.shdiff --git a/docker_healthcheck.js b/docker_healthcheck.jsnew file mode 100755index 0000000000..eeceea5840--- /dev/null+++ b/docker_healthcheck.js@@ -0,0 +1,27 @@+const http = require("http");+const config = require("./src/services/config");++if (config.https) {+ // built-in TLS (terminated by trilium) is not supported yet, PRs are welcome+ // for reverse proxy terminated TLS this will works since config.https will be false+ process.exit(0);+ return;+}++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 => {+ console.log(`STATUS: ${res.statusCode}`);+ if (res.statusCode === 200) {+ process.exit(0);+ } else {+ process.exit(1);+ }+});+request.on("error", err => {+ console.log("ERROR");+ process.exit(1);+});+request.end();\ No newline at end of file