mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 17:52:51 +00:00
Handle trying to remove already stopped/removed containers gracefully.
This commit is contained in:
parent
7072b1df96
commit
e64e6e6dbe
@ -47,12 +47,20 @@ exports.kill = kill = (app) ->
|
||||
Promise.all(
|
||||
containers
|
||||
.filter (container) -> container.Image is "#{app.imageId}:latest"
|
||||
.map (container) -> docker.getContainer(container.Id)
|
||||
.map (container) ->
|
||||
console.log("Stopping and deleting container:", container)
|
||||
container = docker.getContainer(container.Id)
|
||||
console.log('Stopping and deleting container:', container)
|
||||
container.stopAsync()
|
||||
.then ->
|
||||
container.removeAsync()
|
||||
.catch (err) ->
|
||||
# 304 means the container was already stopped - so we can just remove it
|
||||
if err.statusCode is 304
|
||||
return container.removeAsync()
|
||||
# 404 means the container doesn't exist, precisely what we want! :D
|
||||
if err is 404
|
||||
return
|
||||
throw err
|
||||
)
|
||||
.tap ->
|
||||
utils.mixpanelTrack('Application stop', app.imageId)
|
||||
|
Loading…
x
Reference in New Issue
Block a user