mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-06-01 15:20:51 +00:00
Make sure all apps are removed before adding new/updating existing, this is to make sure any ports they use have been freed in case they're needed by the new/updated apps.
Conflicts: src/application.coffee
This commit is contained in:
parent
97d2771826
commit
38481f524d
@ -151,25 +151,26 @@ exports.update = ->
|
|||||||
return !_.isEqual(remoteApps[imageId], apps[imageId])
|
return !_.isEqual(remoteApps[imageId], apps[imageId])
|
||||||
console.log(toBeUpdated)
|
console.log(toBeUpdated)
|
||||||
|
|
||||||
# Install the apps and add each to the db as they succeed
|
# Delete all the ones to remove in one go
|
||||||
promises = toBeInstalled.map (imageId) ->
|
Promise.map toBeRemoved, (imageId) ->
|
||||||
app = remoteApps[imageId]
|
kill(apps[imageId])
|
||||||
start(app)
|
|
||||||
.then ->
|
.then ->
|
||||||
knex('app').insert(app)
|
knex('app').where('imageId', imageId).delete()
|
||||||
# And restart updated apps and update db as they succeed
|
|
||||||
promises = promises.concat toBeUpdated.map (imageId) ->
|
|
||||||
app = remoteApps[imageId]
|
|
||||||
restart(app)
|
|
||||||
.then ->
|
|
||||||
knex('app').update(app).where(imageId: app.imageId)
|
|
||||||
# And delete all the ones to remove in one go
|
|
||||||
promises.push(
|
|
||||||
Promise.map(toBeRemoved, (imageId) -> kill(apps[imageId]))
|
|
||||||
.then ->
|
|
||||||
knex('app').whereIn('imageId', toBeRemoved).delete()
|
|
||||||
)
|
)
|
||||||
Promise.all(promises)
|
.then ->
|
||||||
|
# Then install the apps and add each to the db as they succeed
|
||||||
|
installingPromises = toBeInstalled.map (imageId) ->
|
||||||
|
app = remoteApps[imageId]
|
||||||
|
start(app)
|
||||||
|
.then ->
|
||||||
|
knex('app').insert(app)
|
||||||
|
# And restart updated apps and update db as they succeed
|
||||||
|
updatingPromises = toBeUpdated.map (imageId) ->
|
||||||
|
app = remoteApps[imageId]
|
||||||
|
restart(app)
|
||||||
|
.then ->
|
||||||
|
knex('app').update(app).where(imageId: app.imageId)
|
||||||
|
Promise.all(installingPromises.concat(updatingPromises))
|
||||||
.finally ->
|
.finally ->
|
||||||
if currentlyUpdating is 2
|
if currentlyUpdating is 2
|
||||||
# If an update is required then schedule it
|
# If an update is required then schedule it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user