mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-31 08:25:36 +00:00
Add nodejs side of enabling/disabling log to display
This commit is contained in:
parent
a8df4c0021
commit
2c5bc8b90a
@ -334,7 +334,7 @@ specialActionEnvVars =
|
||||
|
||||
executedSpecialActionEnvVars = {}
|
||||
|
||||
executeSpecialActionsAndBootConfig = (env) ->
|
||||
executeSpecialActionsAndHostConfig = (env) ->
|
||||
Promise.try ->
|
||||
_.map specialActionEnvVars, (specialActionCallback, key) ->
|
||||
if env[key]? && specialActionCallback?
|
||||
@ -342,10 +342,10 @@ executeSpecialActionsAndBootConfig = (env) ->
|
||||
if !_.has(executedSpecialActionEnvVars, key) or executedSpecialActionEnvVars[key] != env[key]
|
||||
specialActionCallback(env[key])
|
||||
executedSpecialActionEnvVars[key] = env[key]
|
||||
bootConfigVars = _.pick env, (val, key) ->
|
||||
return _.startsWith(key, device.bootConfigEnvVarPrefix)
|
||||
if !_.isEmpty(bootConfigVars)
|
||||
device.setBootConfig(bootConfigVars)
|
||||
hostConfigVars = _.pick env, (val, key) ->
|
||||
return _.startsWith(key, device.hostConfigEnvVarPrefix)
|
||||
if !_.isEmpty(hostConfigVars)
|
||||
device.setHostConfig(hostConfigVars)
|
||||
|
||||
wrapAsError = (err) ->
|
||||
return err if _.isError(err)
|
||||
@ -527,7 +527,7 @@ application.update = update = (force) ->
|
||||
# Run special functions against variables if remoteAppEnvs has the corresponding variable function mapping.
|
||||
Promise.map appsWithChangedEnvs, (appId) ->
|
||||
Promise.using lockUpdates(remoteApps[appId], force), ->
|
||||
executeSpecialActionsAndBootConfig(remoteAppEnvs[appId])
|
||||
executeSpecialActionsAndHostConfig(remoteAppEnvs[appId])
|
||||
.then ->
|
||||
# If an env var shouldn't cause a restart but requires an action, we should still
|
||||
# save the new env to the DB
|
||||
@ -613,7 +613,7 @@ application.initialize = ->
|
||||
knex('app').select()
|
||||
.then (apps) ->
|
||||
Promise.map apps, (app) ->
|
||||
executeSpecialActionsAndBootConfig(JSON.parse(app.env))
|
||||
executeSpecialActionsAndHostConfig(JSON.parse(app.env))
|
||||
.then ->
|
||||
unlockAndStart(app)
|
||||
.catch (error) ->
|
||||
|
@ -38,7 +38,8 @@ exports.getID = do ->
|
||||
rebootDevice = ->
|
||||
request.postAsync(config.gosuperAddress + '/v1/reboot')
|
||||
|
||||
exports.bootConfigEnvVarPrefix = bootConfigEnvVarPrefix = 'RESIN_HOST_CONFIG_'
|
||||
exports.hostConfigEnvVarPrefix = hostConfigEnvVarPrefix = 'RESIN_HOST_'
|
||||
bootConfigEnvVarPrefix = 'RESIN_HOST_CONFIG_'
|
||||
bootBlockDevice = '/dev/mmcblk0p1'
|
||||
bootMountPoint = '/mnt/root/boot'
|
||||
bootConfigPath = bootMountPoint + '/config.txt'
|
||||
@ -69,7 +70,23 @@ parseBootConfigFromEnv = (env) ->
|
||||
parsedEnv = _.omit(parsedEnv, forbiddenConfigKeys)
|
||||
return parsedEnv
|
||||
|
||||
exports.setBootConfig = (env) ->
|
||||
exports.setHostConfig = (env) ->
|
||||
Promise.join setBootConfig(env), setLogToDisplay(env), (bootConfigApplied, logToDisplayChanged) ->
|
||||
rebootDevice() if bootConfigApplied or logToDisplayChanged
|
||||
|
||||
setLogToDisplay = (env) ->
|
||||
if env['RESIN_HOST_LOG_TO_DISPLAY']?
|
||||
request.postAsync(config.gosuperAddress + '/v1/set-log-to-display')
|
||||
.spread (response, body) ->
|
||||
if response.statusCode != 200
|
||||
console.log('Error setting log to display:', body, "Status:", response.statusCode)
|
||||
return false
|
||||
else
|
||||
return body.Data
|
||||
else
|
||||
return false
|
||||
|
||||
setBootConfig = (env) ->
|
||||
device.getDeviceType()
|
||||
.then (deviceType) ->
|
||||
throw new Error('This is not a Raspberry Pi') if !_.startsWith(deviceType, 'raspberry-pi')
|
||||
@ -112,9 +129,10 @@ exports.setBootConfig = (env) ->
|
||||
.then ->
|
||||
execAsync('sync')
|
||||
.then ->
|
||||
rebootDevice()
|
||||
return true
|
||||
.catch (err) ->
|
||||
console.log('Will not set boot config: ', err)
|
||||
return false
|
||||
|
||||
exports.getDeviceType = do ->
|
||||
deviceTypePromise = null
|
||||
|
Loading…
x
Reference in New Issue
Block a user