mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-22 06:57:49 +00:00
Merge pull request #38 from resin-io/37-save-after-starting
Only save the app if starting the container was successful
This commit is contained in:
commit
d0ddfd8532
@ -1,3 +1,5 @@
|
||||
* Only save the app if starting the container was successful [Pablo]
|
||||
|
||||
# v1.3.0
|
||||
|
||||
* Remove volumes when removing a container [Pablo]
|
||||
|
@ -201,13 +201,6 @@ application.start = start = (app) ->
|
||||
.catch (err) ->
|
||||
logSystemEvent(logTypes.installAppError, app, err)
|
||||
throw err
|
||||
.tap (container) ->
|
||||
# Update the app info the moment we create the container, even if then starting the container fails. This
|
||||
# stops issues with constantly creating new containers for an image that fails to start.
|
||||
app.containerId = container.id
|
||||
knex('app').update(app).where(appId: app.appId)
|
||||
.then (affectedRows) ->
|
||||
knex('app').insert(app) if affectedRows == 0
|
||||
.tap (container) ->
|
||||
logSystemEvent(logTypes.startApp, app)
|
||||
device.updateState(status: 'Starting')
|
||||
@ -226,11 +219,20 @@ application.start = start = (app) ->
|
||||
# 304 means the container was already started, precisely what we want :)
|
||||
if statusCode is '304'
|
||||
return
|
||||
# If starting the container failed, we remove it so that it doesn't litter
|
||||
container.removeAsync(v: true)
|
||||
.finally ->
|
||||
logSystemEvent(logTypes.startAppError, app, err)
|
||||
throw err
|
||||
.then ->
|
||||
device.updateState(commit: app.commit)
|
||||
logger.attach(app)
|
||||
.tap (container) ->
|
||||
# Update the app info, only if starting the container worked.
|
||||
app.containerId = container.id
|
||||
knex('app').update(app).where(appId: app.appId)
|
||||
.then (affectedRows) ->
|
||||
knex('app').insert(app) if affectedRows == 0
|
||||
.tap ->
|
||||
logSystemEvent(logTypes.startAppSuccess, app)
|
||||
.finally ->
|
||||
|
Loading…
Reference in New Issue
Block a user