mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-20 14:13:08 +00:00
Report the device status to the API
This commit is contained in:
parent
c436d8d5c0
commit
3ef5a86344
@ -41,6 +41,7 @@ publish = do ->
|
|||||||
|
|
||||||
exports.kill = kill = (app) ->
|
exports.kill = kill = (app) ->
|
||||||
utils.mixpanelTrack('Application kill', app)
|
utils.mixpanelTrack('Application kill', app)
|
||||||
|
updateDeviceInfo(status: 'Stopping')
|
||||||
docker.listContainersAsync(all: 1)
|
docker.listContainersAsync(all: 1)
|
||||||
.then (containers) ->
|
.then (containers) ->
|
||||||
Promise.all(
|
Promise.all(
|
||||||
@ -55,6 +56,8 @@ exports.kill = kill = (app) ->
|
|||||||
)
|
)
|
||||||
.tap ->
|
.tap ->
|
||||||
utils.mixpanelTrack('Application stop', app.imageId)
|
utils.mixpanelTrack('Application stop', app.imageId)
|
||||||
|
.finally ->
|
||||||
|
updateDeviceInfo(status: 'Idle')
|
||||||
|
|
||||||
isValidPort = (port) ->
|
isValidPort = (port) ->
|
||||||
maybePort = parseInt(port, 10)
|
maybePort = parseInt(port, 10)
|
||||||
@ -64,6 +67,7 @@ exports.start = start = (app) ->
|
|||||||
docker.getImage(app.imageId).inspectAsync()
|
docker.getImage(app.imageId).inspectAsync()
|
||||||
.catch (error) ->
|
.catch (error) ->
|
||||||
utils.mixpanelTrack('Application install', app)
|
utils.mixpanelTrack('Application install', app)
|
||||||
|
updateDeviceInfo(status: 'Downloading')
|
||||||
docker.createImageAsync(fromImage: app.imageId)
|
docker.createImageAsync(fromImage: app.imageId)
|
||||||
.then (stream) ->
|
.then (stream) ->
|
||||||
return new Promise (resolve, reject) ->
|
return new Promise (resolve, reject) ->
|
||||||
@ -76,6 +80,7 @@ exports.start = start = (app) ->
|
|||||||
stream.on('end', resolve)
|
stream.on('end', resolve)
|
||||||
.then ->
|
.then ->
|
||||||
console.log("Creating container:", app.imageId)
|
console.log("Creating container:", app.imageId)
|
||||||
|
updateDeviceInfo(status: 'Starting')
|
||||||
ports = {}
|
ports = {}
|
||||||
# Parse the env vars before trying to access them, that's because they have to be stringified for knex..
|
# Parse the env vars before trying to access them, that's because they have to be stringified for knex..
|
||||||
env = JSON.parse(app.env)
|
env = JSON.parse(app.env)
|
||||||
@ -123,6 +128,8 @@ exports.start = start = (app) ->
|
|||||||
)
|
)
|
||||||
.tap ->
|
.tap ->
|
||||||
utils.mixpanelTrack('Application start', app.imageId)
|
utils.mixpanelTrack('Application start', app.imageId)
|
||||||
|
.finally ->
|
||||||
|
updateDeviceInfo(status: 'Idle')
|
||||||
|
|
||||||
exports.restart = restart = (app) ->
|
exports.restart = restart = (app) ->
|
||||||
kill(app)
|
kill(app)
|
||||||
@ -138,6 +145,7 @@ exports.update = ->
|
|||||||
# Mark an update required after the current.
|
# Mark an update required after the current.
|
||||||
currentlyUpdating = 2
|
currentlyUpdating = 2
|
||||||
return
|
return
|
||||||
|
updateDeviceInfo(status: 'Checking Updates')
|
||||||
currentlyUpdating = 1
|
currentlyUpdating = 1
|
||||||
Promise.all([
|
Promise.all([
|
||||||
knex('config').select('value').where(key: 'apiKey')
|
knex('config').select('value').where(key: 'apiKey')
|
||||||
@ -217,6 +225,7 @@ exports.update = ->
|
|||||||
knex('app').update(app).where(imageId: app.imageId)
|
knex('app').update(app).where(imageId: app.imageId)
|
||||||
Promise.all(installingPromises.concat(updatingPromises))
|
Promise.all(installingPromises.concat(updatingPromises))
|
||||||
.finally ->
|
.finally ->
|
||||||
|
updateDeviceInfo(status: 'Idle')
|
||||||
if currentlyUpdating is 2
|
if currentlyUpdating is 2
|
||||||
# If an update is required then schedule it
|
# If an update is required then schedule it
|
||||||
setTimeout(exports.update)
|
setTimeout(exports.update)
|
||||||
|
Loading…
Reference in New Issue
Block a user