mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-25 08:21:07 +00:00
Make the supervisor container remove itself rather than just exiting when launching a new supervisor.
This commit is contained in:
parent
cd7ee9b82f
commit
6c9ccfcb8c
@ -20,9 +20,8 @@ getContainerId = ->
|
|||||||
.catch (err) ->
|
.catch (err) ->
|
||||||
return process.env.HOSTNAME
|
return process.env.HOSTNAME
|
||||||
|
|
||||||
getCurrentContainer = ->
|
currentContainer = getContainerId().then (containerId) ->
|
||||||
getContainerId().then (containerId) ->
|
docker.getContainer(containerId)
|
||||||
docker.getContainer(containerId).inspectAsync()
|
|
||||||
|
|
||||||
startNewSupervisor = (currentSupervisor, waitForSuccess = true) ->
|
startNewSupervisor = (currentSupervisor, waitForSuccess = true) ->
|
||||||
console.log('Creating supervisor container:', localImage)
|
console.log('Creating supervisor container:', localImage)
|
||||||
@ -64,10 +63,18 @@ startNewSupervisor = (currentSupervisor, waitForSuccess = true) ->
|
|||||||
throw e
|
throw e
|
||||||
.then ->
|
.then ->
|
||||||
# We've started the new container, so we're done here! #pray
|
# We've started the new container, so we're done here! #pray
|
||||||
console.log('Exiting to let the new supervisor take over')
|
console.log('Removing our container and letting the new supervisor take over')
|
||||||
|
currentContainer.then (container) ->
|
||||||
|
container.removeAsync(force: true)
|
||||||
|
.finally ->
|
||||||
|
# This should never really be reached as docker should already have terminated us,
|
||||||
|
# but in case it hasn't, then we'll just commit harakiri
|
||||||
|
console.log('And process.exiting..')
|
||||||
process.exit()
|
process.exit()
|
||||||
|
|
||||||
currentSupervisor = getCurrentContainer().tap (currentSupervisor) ->
|
currentSupervisorConfig = currentContainer.then (container) ->
|
||||||
|
container.inspectAsync()
|
||||||
|
.tap (currentSupervisor) ->
|
||||||
# The volume keys are the important bit.
|
# The volume keys are the important bit.
|
||||||
expectedVolumes = _.sortBy(_.keys(config.supervisorContainer.Volumes))
|
expectedVolumes = _.sortBy(_.keys(config.supervisorContainer.Volumes))
|
||||||
actualVolumes = _.sortBy(_.keys(currentSupervisor.Volumes))
|
actualVolumes = _.sortBy(_.keys(currentSupervisor.Volumes))
|
||||||
@ -88,7 +95,7 @@ currentSupervisor = getCurrentContainer().tap (currentSupervisor) ->
|
|||||||
restart()
|
restart()
|
||||||
|
|
||||||
# This is a promise that resolves when we have fully initialised.
|
# This is a promise that resolves when we have fully initialised.
|
||||||
exports.initialised = currentSupervisor.then (currentSupervisor) ->
|
exports.initialised = currentSupervisorConfig.then (currentSupervisor) ->
|
||||||
utils = require './utils'
|
utils = require './utils'
|
||||||
JSONStream = require 'JSONStream'
|
JSONStream = require 'JSONStream'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user