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 <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2018-10-16 11:36:26 +02:00 committed by Pablo Carranza Velez
parent 8003f25c3d
commit 802025c01f
2 changed files with 24 additions and 5 deletions

View File

@ -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)

View File

@ -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]: { } }