Health check
COPY ./healthcheck.sh ./
COPY ./healthcheck.js ./
HEALTHCHECK CMD /opt/orbs/healthcheck.shHEALTHCHECK example
#!/bin/sh
node ./healthcheck.jsconst fs = require('fs');
try {
// read json file to JS Object
const status = JSON.parse(fs.readFileSync('./status/status.json').toString());
// check how many seconds ago since the file was written
const updatedAgoSeconds = (new Date().getTime() - new Date(status.Timestamp).getTime()) / 1000;
// return error in case it hasn't been written in the last 5 minutes
if (updatedAgoSeconds > 5 * 60) {
console.log(`Timestamp was not updated in status.json for ${updatedAgoSeconds} seconds.`);
process.exit(128);
}
} catch (err) {
// exception throws in the following cases:
// - status/status.json does not exist
// - status/status.json does not follow expected json format
console.log(err.stack);
process.exit(0); // don't restart in this case, maybe service isn't ready
}
// all good
process.exit(0);Last updated