From 802025c01fe75cf33dd91e2a5fe2ab4b06535854 Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 16 Oct 2018 11:36:26 +0200 Subject: [PATCH] Make handover-complete an alternative to the resin-kill-me file Also fixes the handover wait (since the service interface for it was missing). We add some logging to this process too. Change-type: minor Signed-off-by: Pablo Carranza Velez --- src/compose/service-manager.coffee | 17 ++++++++++++----- src/compose/service.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/compose/service-manager.coffee b/src/compose/service-manager.coffee index 17ed1653..dfeca1b8 100644 --- a/src/compose/service-manager.coffee +++ b/src/compose/service-manager.coffee @@ -227,16 +227,23 @@ module.exports = class ServiceManager extends EventEmitter timeout = checkInt(timeout, positive: true) ? 60000 deadline = Date.now() + timeout - killmePath = service.killmeFullPathOnHost() + handoverCompletePaths = service.handoverCompleteFullPathsOnHost() wait = -> - fs.statAsync(killmePath) - .then -> - fs.unlinkAsync(killmePath).catch(_.noop) - .catch (err) -> + Promise.any _.map handoverCompletePaths, (file) -> + fs.statAsync(file) + .then -> + fs.unlinkAsync(handoverCompletePaths).catch(_.noop) + .catch -> if Date.now() < deadline Promise.delay(pollInterval).then(wait) + else + console.log('Handover timeout has passed, assuming handover was completed') + + console.log('Waiting for handover to be completed') wait() + .then -> + console.log('Handover complete') prepareForHandover: (service) => @get(service) diff --git a/src/compose/service.ts b/src/compose/service.ts index c591b8ed..976ac7b8 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -19,6 +19,7 @@ import * as ComposeUtils from './utils'; import * as updateLock from '../lib/update-lock'; import { sanitiseComposeConfig } from './sanitise'; +import * as constants from '../lib/constants'; export class Service { @@ -655,6 +656,17 @@ export class Service { return _.reject(validVolumes, _.isNil); } + public handoverCompleteFullPathsOnHost(): string[] { + return [ + path.join(handoverCompletePathOnHost(), 'handover-complete'), + path.join(handoverCompletePathOnHost(), 'resin-kill-me'), + ]; + } + + private handoverCompletePathOnHost(): string { + return path.join(constants.rootMountPoint, updateLock.lockPath(this.appId, this.serviceName)); + } + private getBindsAndVolumes(): { binds: string[], volumes: { [volName: string]: { } }