mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-04 08:40:49 +00:00
On startup, only attach to logs for running containers, and remove any containers marked as dead
Closes #611 Change-Type: patch Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
parent
2c92a4de02
commit
6c4eaff02f
@ -266,6 +266,9 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
delete @_containerStarted[step.current.containerId]
|
delete @_containerStarted[step.current.containerId]
|
||||||
if step.options?.removeImage
|
if step.options?.removeImage
|
||||||
@images.removeByDockerId(step.current.image)
|
@images.removeByDockerId(step.current.image)
|
||||||
|
remove: (step) =>
|
||||||
|
# Only called for dead containers, so no need to take locks or anything
|
||||||
|
@services.remove(step.current)
|
||||||
updateMetadata: (step, { force = false, skipLock = false } = {}) =>
|
updateMetadata: (step, { force = false, skipLock = false } = {}) =>
|
||||||
skipLock or= checkTruthy(step.current.labels['io.resin.legacy-container'])
|
skipLock or= checkTruthy(step.current.labels['io.resin.legacy-container'])
|
||||||
@_lockingIfNecessary step.current.appId, { force, skipLock: skipLock or step.options?.skipLock }, =>
|
@_lockingIfNecessary step.current.appId, { force, skipLock: skipLock or step.options?.skipLock }, =>
|
||||||
@ -678,6 +681,10 @@ module.exports = class ApplicationManager extends EventEmitter
|
|||||||
# There is already a kill step in progress for this service, so we wait
|
# There is already a kill step in progress for this service, so we wait
|
||||||
return { action: 'noop' }
|
return { action: 'noop' }
|
||||||
|
|
||||||
|
if current?.status == 'Dead'
|
||||||
|
# Dead containers have to be removed
|
||||||
|
return serviceAction('remove', current.serviceId, current)
|
||||||
|
|
||||||
needsDownload = !_.some availableImages, (image) =>
|
needsDownload = !_.some availableImages, (image) =>
|
||||||
image.dockerImageId == target?.image or @images.isSameImage(image, { name: target.imageName })
|
image.dockerImageId == target?.image or @images.isSameImage(image, { name: target.imageName })
|
||||||
|
|
||||||
|
@ -78,6 +78,15 @@ module.exports = class ServiceManager extends EventEmitter
|
|||||||
kill: (service, { removeContainer = true, wait = false } = {}) =>
|
kill: (service, { removeContainer = true, wait = false } = {}) =>
|
||||||
@_killContainer(service.containerId, service, { removeContainer, wait })
|
@_killContainer(service.containerId, service, { removeContainer, wait })
|
||||||
|
|
||||||
|
remove: (service) =>
|
||||||
|
@logger.logSystemEvent(logTypes.removeDeadService, { service })
|
||||||
|
@get(service)
|
||||||
|
.then (existingService) =>
|
||||||
|
@docker.getContainer(existingService.containerId).remove(v: true)
|
||||||
|
.catchReturn(NotFoundError, null)
|
||||||
|
.tapCatch (err) =>
|
||||||
|
@logger.logSystemEvent(logTypes.removeDeadServiceError, { service, error: err })
|
||||||
|
|
||||||
getAllByAppId: (appId) =>
|
getAllByAppId: (appId) =>
|
||||||
@getAll("io.resin.app-id=#{appId}")
|
@getAll("io.resin.app-id=#{appId}")
|
||||||
|
|
||||||
@ -278,5 +287,6 @@ module.exports = class ServiceManager extends EventEmitter
|
|||||||
attachToRunning: =>
|
attachToRunning: =>
|
||||||
@getAll()
|
@getAll()
|
||||||
.map (service) =>
|
.map (service) =>
|
||||||
|
if service.status == 'Running'
|
||||||
@logger.logSystemEvent(logTypes.startServiceNoop, { service })
|
@logger.logSystemEvent(logTypes.startServiceNoop, { service })
|
||||||
@logger.attach(@docker, service.containerId, service)
|
@logger.attach(@docker, service.containerId, service)
|
||||||
|
@ -429,6 +429,8 @@ module.exports = class Service
|
|||||||
status = 'Running'
|
status = 'Running'
|
||||||
else if container.State.Status == 'created'
|
else if container.State.Status == 'created'
|
||||||
status = 'Installed'
|
status = 'Installed'
|
||||||
|
else if container.State.Status == 'dead'
|
||||||
|
status = 'Dead'
|
||||||
else
|
else
|
||||||
status = 'Stopped'
|
status = 'Stopped'
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@ module.exports =
|
|||||||
eventName: 'Service stop error'
|
eventName: 'Service stop error'
|
||||||
humanName: 'Failed to kill service'
|
humanName: 'Failed to kill service'
|
||||||
|
|
||||||
|
removeDeadService:
|
||||||
|
eventName: 'Remove dead container'
|
||||||
|
humanName: 'Removing dead container'
|
||||||
|
removeDeadServiceError:
|
||||||
|
eventName: 'Remove dead container error'
|
||||||
|
humanName: 'Error removing dead container'
|
||||||
|
|
||||||
downloadImage:
|
downloadImage:
|
||||||
eventName: 'Docker image download'
|
eventName: 'Docker image download'
|
||||||
humanName: 'Downloading image'
|
humanName: 'Downloading image'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user