mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
reimplement docker healtcheck into node.js to take into account configuration, #3582
This commit is contained in:
parent
a9296e2a39
commit
260bc93a66
@ -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 1
|
@ -39,4 +39,4 @@ RUN adduser -s /bin/false node; exit 0
|
||||
EXPOSE 8080
|
||||
CMD [ "./start-docker.sh" ]
|
||||
|
||||
HEALTHCHECK CMD sh DockerHealthcheck.sh
|
||||
HEALTHCHECK CMD node docker_healthcheck.sh
|
||||
|
27
docker_healthcheck.js
Executable file
27
docker_healthcheck.js
Executable file
@ -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();
|
Loading…
x
Reference in New Issue
Block a user