Skip to content

Commit 01148cf

Browse files
authored
Merge pull request #21 from rumd3x/hotfix/healthcheck
Healthcheck fix + some fine tuning and extra check
2 parents 7f39176 + 4368742 commit 01148cf

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN mkdir -p /usr/src/app/.node-persist
1616
RUN touch /usr/src/app/.node-persist/jobs.crontab
1717
RUN cat /usr/src/app/.node-persist/jobs.crontab | crontab
1818

19-
HEALTHCHECK --interval=20s --timeout=10s --start-period=5s --retries=3 CMD curl --connect-timeout 4 --max-time 6 --fail -I localhost/probe
19+
HEALTHCHECK --interval=60s --timeout=3s --start-period=5s --retries=3 CMD curl --connect-timeout 1 --max-time 2 --fail -I localhost/probe
2020

2121
EXPOSE 80
2222

routes/routes.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ const register = (app) => {
1919
});
2020

2121
app.get("/probe", (req, res) => {
22-
let cronStatus = utils.getCronStatus();
22+
let cron = utils.getCronStatus();
23+
let docker = utils.getDockerStatus();
2324

24-
if (cronStatus.status !== "cron is running.") {
25-
res.status(500);
25+
if (!cron.healthy || !docker.healthy) {
26+
res.status(500).json({"data": "NOK", "message": "Healthcheck failed."});
2627
return;
2728
}
2829

29-
res.status(200);
30+
res.status(200).json({"data": "OK", "message": "Healthcheck passed."});
3031
});
3132

3233
app.get("/api/time", async (req, res) => {

utils/utils.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ const getLogs = (job) => {
4949
}
5050

5151
const getCronStatus = () => {
52+
let cronServiceStatus = shell.exec("service cron status", { silent: true });
5253
return {
53-
entries: shell.exec("crontab -l"),
54-
status: shell.exec("service cron status")
54+
entries: shell.exec("crontab -l", { silent: true }),
55+
status: cronServiceStatus,
56+
healthy: cronServiceStatus.code === 0
5557
};
5658
}
5759

58-
module.exports = { getBiggest, rewriteCronFile, getLogs, getCronStatus }
60+
const getDockerStatus = () => {
61+
return {
62+
healthy: shell.exec("docker info", { silent: true }).code === 0
63+
};
64+
};
65+
66+
module.exports = { getBiggest, rewriteCronFile, getLogs, getCronStatus, getDockerStatus }

0 commit comments

Comments
 (0)