forked from TriliumNext/Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_healthcheck.ts
executable file
·42 lines (35 loc) · 1.15 KB
/
docker_healthcheck.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import http from "http";
import ini from "ini";
import fs from "fs";
import dataDir from './src/services/data_dir.js';
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);
}
import port from './src/services/port.js';
import host from './src/services/host.js';
const options: http.RequestOptions = { timeout: 2000 };
const callback: (res: http.IncomingMessage) => void = res => {
console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode === 200) {
process.exit(0);
} else {
process.exit(1);
}
};
let request;
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);
}
request.on("error", err => {
console.log("ERROR");
process.exit(1);
});
request.end();