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