Allow the enabling and disabling of persistent logging via env var

Closes: #698
Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-07-17 12:21:27 +01:00
parent 0e29e5f6f7
commit 1604fdf276
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
3 changed files with 27 additions and 7 deletions

View File

@ -44,6 +44,7 @@ class Config extends EventEmitter {
bootstrapRetryDelay: { source: 'config.json', default: 30000 },
supervisorOfflineMode: { source: 'config.json', default: false },
hostname: { source: 'config.json', mutable: true },
persistentLogging: { source: 'config.json', default: false, mutable: true },
version: { source: 'func' },
currentApiKey: { source: 'func' },

View File

@ -24,14 +24,20 @@ module.exports = class DeviceConfig
deltaVersion: { envVarName: 'RESIN_SUPERVISOR_DELTA_VERSION', varType: 'int', defaultValue: '2' }
lockOverride: { envVarName: 'RESIN_SUPERVISOR_OVERRIDE_LOCK', varType: 'bool', defaultValue: 'false' }
nativeLogger: { envVarName: 'RESIN_SUPERVISOR_NATIVE_LOGGER', varType: 'bool', defaultValue: 'true' }
persistentLogging: { envVarName: 'RESIN_SUPERVISOR_PERSISTENT_LOGGING', varType: 'bool', defaultValue: 'false', rebootRequired: true }
}
@validKeys = [ 'RESIN_SUPERVISOR_VPN_CONTROL', 'RESIN_OVERRIDE_LOCK' ].concat(_.map(@configKeys, 'envVarName'))
@validKeys = [
'RESIN_SUPERVISOR_VPN_CONTROL',
'RESIN_OVERRIDE_LOCK',
].concat(_.map(@configKeys, 'envVarName'))
@actionExecutors = {
changeConfig: (step) =>
@logger.logConfigChange(step.humanReadableTarget)
@config.set(step.target)
.then =>
@logger.logConfigChange(step.humanReadableTarget, { success: true })
if step.rebootRequired
@rebootRequired = true
.tapCatch (err) =>
@logger.logConfigChange(step.humanReadableTarget, { err })
setVPNEnabled: (step, { initial = false } = {}) =>
@ -140,29 +146,37 @@ module.exports = class DeviceConfig
# If the legacy lock override is used, place it as the new variable
if checkTruthy(target['RESIN_OVERRIDE_LOCK'])
target['RESIN_SUPERVISOR_OVERRIDE_LOCK'] = target['RESIN_OVERRIDE_LOCK']
for own key, { envVarName, varType } of @configKeys
reboot = false
for own key, { envVarName, varType, rebootRequired } of @configKeys
if !match[varType](current[envVarName], target[envVarName])
configChanges[key] = target[envVarName]
humanReadableConfigChanges[envVarName] = target[envVarName]
reboot = reboot || (rebootRequired ? false)
if !_.isEmpty(configChanges)
steps.push({
action: 'changeConfig'
target: configChanges
humanReadableTarget: humanReadableConfigChanges
rebootRequired: reboot
})
return
# Check if we need to perform special case actions for the VPN
if !checkTruthy(offlineMode) &&
!_.isEmpty(target['RESIN_SUPERVISOR_VPN_CONTROL']) &&
checkTruthy(current['RESIN_SUPERVISOR_VPN_CONTROL']) != checkTruthy(target['RESIN_SUPERVISOR_VPN_CONTROL'])
steps.push({
action: 'setVPNEnabled'
target: target['RESIN_SUPERVISOR_VPN_CONTROL']
})
@checkBoolChanged(current, target, 'RESIN_SUPERVISOR_VPN_CONTROL')
steps.push({
action: 'setVPNEnabled'
target: target['RESIN_SUPERVISOR_VPN_CONTROL']
})
# Do we need to change the boot config?
if @bootConfigChangeRequired(configBackend, current, target)
steps.push({
action: 'setBootConfig'
target
})
if !_.isEmpty(steps)
return
if @rebootRequired
@ -210,3 +224,6 @@ module.exports = class DeviceConfig
systemd.startService(vpnServiceName)
else
systemd.stopService(vpnServiceName)
checkBoolChanged: (current, target, key) ->
checkTruthy(current[key]) != checkTruthy(target[key])

View File

@ -46,6 +46,7 @@ testTarget1 = {
'RESIN_SUPERVISOR_OVERRIDE_LOCK': 'false'
'RESIN_SUPERVISOR_POLL_INTERVAL': '60000'
'RESIN_SUPERVISOR_VPN_CONTROL': 'true'
'RESIN_SUPERVISOR_PERSISTENT_LOGGING': 'false'
}
apps: {
'1234': {
@ -128,6 +129,7 @@ testTargetWithDefaults2 = {
'RESIN_SUPERVISOR_OVERRIDE_LOCK': 'false'
'RESIN_SUPERVISOR_POLL_INTERVAL': '60000'
'RESIN_SUPERVISOR_VPN_CONTROL': 'true'
'RESIN_SUPERVISOR_PERSISTENT_LOGGING': 'false'
}
apps: {
'1234': {