mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-31 23:00:48 +00:00
Fix handling of systemd errors when polling for log to display
Change-type: patch Closes: #610 Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
parent
6229e3ee61
commit
96d7bbefd0
@ -34,7 +34,6 @@ forbiddenConfigKeys = [
|
|||||||
]
|
]
|
||||||
arrayConfigKeys = [ 'dtparam', 'dtoverlay', 'device_tree_param', 'device_tree_overlay' ]
|
arrayConfigKeys = [ 'dtparam', 'dtoverlay', 'device_tree_param', 'device_tree_overlay' ]
|
||||||
|
|
||||||
logToDisplayServiceName = 'resin-info@tty1'
|
|
||||||
vpnServiceName = 'openvpn-resin'
|
vpnServiceName = 'openvpn-resin'
|
||||||
|
|
||||||
module.exports = class DeviceConfig
|
module.exports = class DeviceConfig
|
||||||
@ -53,7 +52,7 @@ module.exports = class DeviceConfig
|
|||||||
lockOverride: { envVarName: 'RESIN_SUPERVISOR_OVERRIDE_LOCK', varType: 'bool', defaultValue: 'false' }
|
lockOverride: { envVarName: 'RESIN_SUPERVISOR_OVERRIDE_LOCK', varType: 'bool', defaultValue: 'false' }
|
||||||
nativeLogger: { envVarName: 'RESIN_SUPERVISOR_NATIVE_LOGGER', varType: 'bool', defaultValue: 'true' }
|
nativeLogger: { envVarName: 'RESIN_SUPERVISOR_NATIVE_LOGGER', varType: 'bool', defaultValue: 'true' }
|
||||||
}
|
}
|
||||||
@validKeys = [ 'RESIN_HOST_LOG_TO_DISPLAY', 'RESIN_SUPERVISOR_VPN_CONTROL', 'RESIN_OVERRIDE_LOCK' ].concat(_.map(@configKeys, 'envVarName'))
|
@validKeys = [ 'RESIN_SUPERVISOR_VPN_CONTROL', 'RESIN_OVERRIDE_LOCK' ].concat(_.map(@configKeys, 'envVarName'))
|
||||||
@actionExecutors = {
|
@actionExecutors = {
|
||||||
changeConfig: (step) =>
|
changeConfig: (step) =>
|
||||||
@logger.logConfigChange(step.humanReadableTarget)
|
@logger.logConfigChange(step.humanReadableTarget)
|
||||||
@ -62,14 +61,6 @@ module.exports = class DeviceConfig
|
|||||||
@logger.logConfigChange(step.humanReadableTarget, { success: true })
|
@logger.logConfigChange(step.humanReadableTarget, { success: true })
|
||||||
.tapCatch (err) =>
|
.tapCatch (err) =>
|
||||||
@logger.logConfigChange(step.humanReadableTarget, { err })
|
@logger.logConfigChange(step.humanReadableTarget, { err })
|
||||||
setLogToDisplay: (step) =>
|
|
||||||
logValue = { RESIN_HOST_LOG_TO_DISPLAY: step.target }
|
|
||||||
@logger.logConfigChange(logValue)
|
|
||||||
@setLogToDisplay(step.target)
|
|
||||||
.then =>
|
|
||||||
@logger.logConfigChange(logValue, { success: true })
|
|
||||||
.tapCatch (err) =>
|
|
||||||
@logger.logConfigChange(logValue, { err })
|
|
||||||
setVPNEnabled: (step, { initial = false } = {}) =>
|
setVPNEnabled: (step, { initial = false } = {}) =>
|
||||||
logValue = { RESIN_SUPERVISOR_VPN_CONTROL: step.target }
|
logValue = { RESIN_SUPERVISOR_VPN_CONTROL: step.target }
|
||||||
if !initial
|
if !initial
|
||||||
@ -104,7 +95,6 @@ module.exports = class DeviceConfig
|
|||||||
return JSON.parse(devConfig.targetValues)
|
return JSON.parse(devConfig.targetValues)
|
||||||
.then (conf) =>
|
.then (conf) =>
|
||||||
conf = @filterConfigKeys(conf)
|
conf = @filterConfigKeys(conf)
|
||||||
conf.RESIN_HOST_LOG_TO_DISPLAY ?= ''
|
|
||||||
if initial or !conf.RESIN_SUPERVISOR_VPN_CONTROL?
|
if initial or !conf.RESIN_SUPERVISOR_VPN_CONTROL?
|
||||||
conf.RESIN_SUPERVISOR_VPN_CONTROL = 'true'
|
conf.RESIN_SUPERVISOR_VPN_CONTROL = 'true'
|
||||||
for own k, { envVarName, defaultValue } of @configKeys
|
for own k, { envVarName, defaultValue } of @configKeys
|
||||||
@ -115,12 +105,10 @@ module.exports = class DeviceConfig
|
|||||||
@config.getMany([ 'deviceType' ].concat(_.keys(@configKeys)))
|
@config.getMany([ 'deviceType' ].concat(_.keys(@configKeys)))
|
||||||
.then (conf) =>
|
.then (conf) =>
|
||||||
Promise.join(
|
Promise.join(
|
||||||
@getLogToDisplay()
|
|
||||||
@getVPNEnabled()
|
@getVPNEnabled()
|
||||||
@getBootConfig(conf.deviceType)
|
@getBootConfig(conf.deviceType)
|
||||||
(logToDisplayStatus, vpnStatus, bootConfig) =>
|
(vpnStatus, bootConfig) =>
|
||||||
currentConf = {
|
currentConf = {
|
||||||
RESIN_HOST_LOG_TO_DISPLAY: (logToDisplayStatus ? '').toString()
|
|
||||||
RESIN_SUPERVISOR_VPN_CONTROL: (vpnStatus ? 'true').toString()
|
RESIN_SUPERVISOR_VPN_CONTROL: (vpnStatus ? 'true').toString()
|
||||||
}
|
}
|
||||||
for own key, { envVarName } of @configKeys
|
for own key, { envVarName } of @configKeys
|
||||||
@ -131,7 +119,6 @@ module.exports = class DeviceConfig
|
|||||||
getDefaults: =>
|
getDefaults: =>
|
||||||
Promise.try =>
|
Promise.try =>
|
||||||
return _.extend({
|
return _.extend({
|
||||||
RESIN_HOST_LOG_TO_DISPLAY: ''
|
|
||||||
RESIN_SUPERVISOR_VPN_CONTROL: 'true'
|
RESIN_SUPERVISOR_VPN_CONTROL: 'true'
|
||||||
}, _.mapValues(_.mapKeys(@configKeys, 'envVarName'), 'defaultValue'))
|
}, _.mapValues(_.mapKeys(@configKeys, 'envVarName'), 'defaultValue'))
|
||||||
|
|
||||||
@ -175,12 +162,6 @@ module.exports = class DeviceConfig
|
|||||||
humanReadableTarget: humanReadableConfigChanges
|
humanReadableTarget: humanReadableConfigChanges
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
if !_.isUndefined(current['RESIN_HOST_LOG_TO_DISPLAY'])
|
|
||||||
if !_.isEmpty(target['RESIN_HOST_LOG_TO_DISPLAY']) && checkTruthy(current['RESIN_HOST_LOG_TO_DISPLAY']) != checkTruthy(target['RESIN_HOST_LOG_TO_DISPLAY'])
|
|
||||||
steps.push({
|
|
||||||
action: 'setLogToDisplay'
|
|
||||||
target: target['RESIN_HOST_LOG_TO_DISPLAY']
|
|
||||||
})
|
|
||||||
if !checkTruthy(offlineMode) &&
|
if !checkTruthy(offlineMode) &&
|
||||||
!_.isEmpty(target['RESIN_SUPERVISOR_VPN_CONTROL']) &&
|
!_.isEmpty(target['RESIN_SUPERVISOR_VPN_CONTROL']) &&
|
||||||
checkTruthy(current['RESIN_SUPERVISOR_VPN_CONTROL']) != checkTruthy(target['RESIN_SUPERVISOR_VPN_CONTROL'])
|
checkTruthy(current['RESIN_SUPERVISOR_VPN_CONTROL']) != checkTruthy(target['RESIN_SUPERVISOR_VPN_CONTROL'])
|
||||||
@ -255,35 +236,6 @@ module.exports = class DeviceConfig
|
|||||||
conf[keyValue[1]] = keyValue[2]
|
conf[keyValue[1]] = keyValue[2]
|
||||||
return @bootConfigToEnv(conf)
|
return @bootConfigToEnv(conf)
|
||||||
|
|
||||||
getLogToDisplay: ->
|
|
||||||
systemd.serviceActiveState(logToDisplayServiceName)
|
|
||||||
.then (activeState) ->
|
|
||||||
return activeState not in [ 'inactive', 'deactivating' ]
|
|
||||||
.catchReturn(UnitNotLoadedError, null)
|
|
||||||
|
|
||||||
setLogToDisplay: (val) =>
|
|
||||||
Promise.try =>
|
|
||||||
enable = checkTruthy(val)
|
|
||||||
if !enable?
|
|
||||||
throw new Error("Invalid value in call to setLogToDisplay: #{val}")
|
|
||||||
@getLogToDisplay()
|
|
||||||
.then (currentState) ->
|
|
||||||
if !currentState? or currentState == enable
|
|
||||||
return false
|
|
||||||
if enable
|
|
||||||
systemd.startService(logToDisplayServiceName)
|
|
||||||
.then ->
|
|
||||||
systemd.enableService(logToDisplayServiceName)
|
|
||||||
.return(true)
|
|
||||||
else
|
|
||||||
systemd.stopService(logToDisplayServiceName)
|
|
||||||
.then ->
|
|
||||||
systemd.disableService(logToDisplayServiceName)
|
|
||||||
.return(true)
|
|
||||||
.tap (changed) =>
|
|
||||||
if changed
|
|
||||||
@rebootRequired = true
|
|
||||||
|
|
||||||
setBootConfig: (deviceType, target) =>
|
setBootConfig: (deviceType, target) =>
|
||||||
Promise.try =>
|
Promise.try =>
|
||||||
conf = @envToBootConfig(target)
|
conf = @envToBootConfig(target)
|
||||||
|
@ -13,7 +13,6 @@ Config = require('../src/config')
|
|||||||
Service = require '../src/compose/service'
|
Service = require '../src/compose/service'
|
||||||
|
|
||||||
mockedInitialConfig = {
|
mockedInitialConfig = {
|
||||||
'RESIN_HOST_LOG_TO_DISPLAY': '1'
|
|
||||||
'RESIN_SUPERVISOR_CONNECTIVITY_CHECK': 'true'
|
'RESIN_SUPERVISOR_CONNECTIVITY_CHECK': 'true'
|
||||||
'RESIN_SUPERVISOR_DELTA': 'false'
|
'RESIN_SUPERVISOR_DELTA': 'false'
|
||||||
'RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT': ''
|
'RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT': ''
|
||||||
@ -32,7 +31,6 @@ testTarget1 = {
|
|||||||
name: 'aDevice'
|
name: 'aDevice'
|
||||||
config: {
|
config: {
|
||||||
'RESIN_HOST_CONFIG_gpu_mem': '256'
|
'RESIN_HOST_CONFIG_gpu_mem': '256'
|
||||||
'RESIN_HOST_LOG_TO_DISPLAY': '0'
|
|
||||||
'RESIN_SUPERVISOR_CONNECTIVITY_CHECK': 'true'
|
'RESIN_SUPERVISOR_CONNECTIVITY_CHECK': 'true'
|
||||||
'RESIN_SUPERVISOR_DELTA': 'false'
|
'RESIN_SUPERVISOR_DELTA': 'false'
|
||||||
'RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT': ''
|
'RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT': ''
|
||||||
@ -78,7 +76,6 @@ testTarget2 = {
|
|||||||
name: 'aDeviceWithDifferentName'
|
name: 'aDeviceWithDifferentName'
|
||||||
config: {
|
config: {
|
||||||
'RESIN_HOST_CONFIG_gpu_mem': '512'
|
'RESIN_HOST_CONFIG_gpu_mem': '512'
|
||||||
'RESIN_HOST_LOG_TO_DISPLAY': '1'
|
|
||||||
}
|
}
|
||||||
apps: {
|
apps: {
|
||||||
'1234': {
|
'1234': {
|
||||||
@ -115,7 +112,6 @@ testTargetWithDefaults2 = {
|
|||||||
name: 'aDeviceWithDifferentName'
|
name: 'aDeviceWithDifferentName'
|
||||||
config: {
|
config: {
|
||||||
'RESIN_HOST_CONFIG_gpu_mem': '512'
|
'RESIN_HOST_CONFIG_gpu_mem': '512'
|
||||||
'RESIN_HOST_LOG_TO_DISPLAY': '1'
|
|
||||||
'RESIN_SUPERVISOR_CONNECTIVITY_CHECK': 'true'
|
'RESIN_SUPERVISOR_CONNECTIVITY_CHECK': 'true'
|
||||||
'RESIN_SUPERVISOR_DELTA': 'false'
|
'RESIN_SUPERVISOR_DELTA': 'false'
|
||||||
'RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT': ''
|
'RESIN_SUPERVISOR_DELTA_APPLY_TIMEOUT': ''
|
||||||
@ -152,7 +148,6 @@ testTargetInvalid = {
|
|||||||
name: 'aDeviceWithDifferentName'
|
name: 'aDeviceWithDifferentName'
|
||||||
config: {
|
config: {
|
||||||
'RESIN_HOST_CONFIG_gpu_mem': '512'
|
'RESIN_HOST_CONFIG_gpu_mem': '512'
|
||||||
'RESIN_HOST_LOG_TO_DISPLAY': '1'
|
|
||||||
}
|
}
|
||||||
apps: [
|
apps: [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user