Merge pull request #63 from NiNiyas/docker-healthcheck

Docker Healthcheck
This commit is contained in:
Louis Lam 2021-07-18 13:47:25 +08:00 committed by GitHub
commit fb3e000dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -31,6 +31,7 @@ RUN npm run build
EXPOSE 3001
VOLUME ["/app/data"]
HEALTHCHECK --interval=5s --timeout=3s --start-period=30s CMD node extra/healthcheck.js
CMD ["npm", "run", "start-server"]
FROM release AS nightly

19
extra/healthcheck.js Normal file
View File

@ -0,0 +1,19 @@
var http = require("http");
var options = {
host: "localhost",
port: "3001",
timeout: 2000,
};
var request = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
if (res.statusCode == 200) {
process.exit(0);
} else {
process.exit(1);
}
});
request.on("error", function (err) {
console.log("ERROR");
process.exit(1);
});
request.end();