trilium/docker_healthcheck.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

const http = require("http");
const ini = require("ini");
const fs = require("fs");
const dataDir = require("./src/services/data_dir");
const config = ini.parse(fs.readFileSync(dataDir.CONFIG_INI_PATH, 'utf-8'));
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);
}
const port = require('./src/services/port');
const host = require('./src/services/host');
2023-03-11 17:57:16 +08:00
2023-03-13 04:37:13 +08:00
const options = { timeout: 2000 };
2023-03-11 17:57:16 +08:00
const callback = res => {
console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode === 200) {
process.exit(0);
} else {
process.exit(1);
}
2023-03-11 17:57:16 +08:00
};
2023-03-13 04:37:13 +08:00
2023-03-11 17:57:16 +08:00
let request;
2023-03-13 04:37:13 +08:00
2023-03-11 17:57:16 +08:00
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);
}
2023-03-13 04:37:13 +08:00
request.on("error", err => {
console.log("ERROR");
process.exit(1);
});
2023-03-11 17:57:16 +08:00
request.end();