From 2210b1be29338a0f25899d0903dcc7f53fa0df46 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Wed, 1 Oct 2014 18:01:35 +0100 Subject: [PATCH] Only wait for success if we're restarting due to an update attempt. If we're restarting for binds/mounts then we're already in a non-working state, and starting the new supervisor may have to wait for bootstrap to complete (which takes an indefinite amount of time to complete, meaning the timeout was killing the new container before it could bootstrap in some cases) --- src/supervisor-update.coffee | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/supervisor-update.coffee b/src/supervisor-update.coffee index e2ce71b1..883cac02 100644 --- a/src/supervisor-update.coffee +++ b/src/supervisor-update.coffee @@ -24,7 +24,7 @@ getCurrentContainer = -> getContainerId().then (containerId) -> docker.getContainer(containerId).inspectAsync() -startNewSupervisor = (currentSupervisor) -> +startNewSupervisor = (currentSupervisor, waitForSuccess = true) -> console.log('Creating supervisor container:', localImage) docker.createContainerAsync( Image: localImage @@ -39,6 +39,8 @@ startNewSupervisor = (currentSupervisor) -> Binds: config.supervisorContainer.Binds ) .then (container) -> + if !waitForSuccess + return # check that next supervisor outputs config.successMessage before this supervisor exits container.attachAsync({ stream: true, stdout: true, stderr: false, tty: true }) .then (stream) -> @@ -76,7 +78,14 @@ currentSupervisor = getCurrentContainer().tap (currentSupervisor) -> # Check all the expected binds and volumes exist, if not then start a new supervisor (which will add them correctly) if !_.isEqual(expectedVolumes, actualVolumes) or !_.isEqual(expectedBinds, actualBinds) console.log('Supervisor restart (for binds/mounts)') - startNewSupervisor(currentSupervisor) + restart = -> + # When restarting for just binds/mounts we just wait for the supervisor updates to start. + startNewSupervisor(currentSupervisor, false) + .catch (err) -> + console.error('Error restarting', err) + # If there's an error just keep attempting to restart to get to a useful state. + restart() + restart() # This is a promise that resolves when we have fully initialised. exports.initialised = currentSupervisor.then (currentSupervisor) ->