Notes/docker_healthcheck.ts

42 lines
1.0 KiB
TypeScript
Raw Normal View History

import http from "http";
import config from "./src/services/config.js";
if (config.Network.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);
}
2025-01-09 18:07:02 +02:00
import port from "./src/services/port.js";
import host from "./src/services/host.js";
2023-03-11 20:57:16 +11:00
const options: http.RequestOptions = { timeout: 2000 };
2023-03-12 21:37:13 +01:00
2025-01-09 18:07:02 +02:00
const callback: (res: http.IncomingMessage) => void = (res) => {
console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode === 200) {
process.exit(0);
} else {
process.exit(1);
}
2023-03-11 20:57:16 +11:00
};
2023-03-12 21:37:13 +01:00
2023-03-11 20:57:16 +11:00
let request;
2023-03-12 21:37:13 +01:00
2025-01-09 18:07:02 +02:00
if (port !== 0) {
// TCP socket.
2023-03-11 20:57:16 +11:00
const url = `http://${host}:${port}/api/health-check`;
request = http.request(url, options, callback);
2025-01-09 18:07:02 +02:00
} else {
// Unix socket.
2023-03-11 20:57:16 +11:00
options.socketPath = host;
2025-01-09 18:07:02 +02:00
options.path = "/api/health-check";
2023-03-11 20:57:16 +11:00
request = http.request(options, callback);
}
2023-03-12 21:37:13 +01:00
2025-01-09 18:07:02 +02:00
request.on("error", (err) => {
console.log("ERROR");
process.exit(1);
});
2023-03-11 20:57:16 +11:00
request.end();