Fix service status

This commit is contained in:
Girish Ramakrishnan
2021-08-26 21:14:49 -07:00
parent 42774eac8c
commit f5c169f881
2 changed files with 7 additions and 10 deletions

View File

@@ -73,19 +73,16 @@ function removePrivateFields(registryConfig) {
return registryConfig;
}
function ping(callback) {
assert.strictEqual(typeof callback, 'function');
async function ping() {
// do not let the request linger
const connection = new Docker({ socketPath: DOCKER_SOCKET_PATH, timeout: 1000 });
connection.ping(function (error, result) {
if (error) return callback(new BoxError(BoxError.DOCKER_ERROR, error));
if (Buffer.isBuffer(result) && result.toString('utf8') === 'OK') return callback(null); // sometimes it returns buffer
if (result === 'OK') return callback(null);
const [error, result] = await safe(connection.ping());
if (error) throw new BoxError(BoxError.DOCKER_ERROR, error);
if (Buffer.isBuffer(result) && result.toString('utf8') === 'OK') return; // sometimes it returns buffer
if (result === 'OK') return;
callback(new BoxError(BoxError.DOCKER_ERROR, 'Unable to ping the docker daemon'));
});
throw new BoxError(BoxError.DOCKER_ERROR, 'Unable to ping the docker daemon');
}
async function getRegistryConfig(image) {