mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 15:32:24 +00:00
Do not persist the uuid when in offline mode, so that the supervisor tries to provision if it goes out of offline mode
We used to store the uuid which would cause the supervisor to not attempt a provisioning even if offline mode was turned off. This was to avoid preloaded apps being reloaded constantly leaving multiple containers. We now avoid persisting the uuid, so that when the supervisor goes out of offline mode it can provision without the need to wipe out the db. We avoid the problem with preloaded apps by not loading them if there's apps already stored on the db. (In the future, apps in the db will only represent target state and we can make preloaded apps be reloaded on every start, but for now we can't do it as long as we store the containerId on the db - deleting an app on the db means losing track of its containerId and therefore leaving an orphaned container) Change-Type: patch Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
parent
3ba7641d17
commit
f0344ca4be
@ -32,21 +32,24 @@ writeAndSyncFile = (path, data) ->
|
||||
|
||||
loadPreloadedApps = ->
|
||||
devConfig = {}
|
||||
knex('app').truncate()
|
||||
.then ->
|
||||
knex('app').select()
|
||||
.then (apps) ->
|
||||
if apps.length > 0
|
||||
console.log('Preloaded apps already loaded, skipping')
|
||||
return
|
||||
fs.readFileAsync(appsPath, 'utf8')
|
||||
.then(JSON.parse)
|
||||
.map (app) ->
|
||||
utils.extendEnvVars(app.env, userConfig.uuid, app.appId, app.name, app.commit)
|
||||
.then (extendedEnv) ->
|
||||
app.env = JSON.stringify(extendedEnv)
|
||||
_.merge(devConfig, app.config)
|
||||
app.config = JSON.stringify(app.config)
|
||||
knex('app').insert(app)
|
||||
.then ->
|
||||
deviceConfig.set({ targetValues: devConfig })
|
||||
.catch (err) ->
|
||||
utils.mixpanelTrack('Loading preloaded apps failed', { error: err })
|
||||
.then(JSON.parse)
|
||||
.map (app) ->
|
||||
utils.extendEnvVars(app.env, userConfig.uuid, app.appId, app.name, app.commit)
|
||||
.then (extendedEnv) ->
|
||||
app.env = JSON.stringify(extendedEnv)
|
||||
_.merge(devConfig, app.config)
|
||||
app.config = JSON.stringify(app.config)
|
||||
knex('app').insert(app)
|
||||
.then ->
|
||||
deviceConfig.set({ targetValues: devConfig })
|
||||
.catch (err) ->
|
||||
utils.mixpanelTrack('Loading preloaded apps failed', { error: err })
|
||||
|
||||
fetchDevice = (apiKey) ->
|
||||
resinApi.get
|
||||
@ -223,11 +226,8 @@ bootstrapper.startBootstrapping = ->
|
||||
.tap ->
|
||||
loadPreloadedApps()
|
||||
.tap (uuid) ->
|
||||
if bootstrapper.offlineMode
|
||||
return knex('config').insert({ key: 'uuid', value: uuid })
|
||||
else
|
||||
bootstrapOrRetry()
|
||||
# Don't wait on bootstrapping here, bootstrapper.done is for that.
|
||||
return
|
||||
bootstrapOrRetry() if !bootstrapper.offlineMode
|
||||
# Don't wait on bootstrapping here, bootstrapper.done is for that.
|
||||
return
|
||||
|
||||
module.exports = bootstrapper
|
||||
|
Loading…
Reference in New Issue
Block a user