diff --git a/src/config.ts b/src/config.ts index 539def43..904b9940 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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' }, diff --git a/src/device-config.coffee b/src/device-config.coffee index 08370b06..c0b2dedf 100644 --- a/src/device-config.coffee +++ b/src/device-config.coffee @@ -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]) diff --git a/test/05-device-state.spec.coffee b/test/05-device-state.spec.coffee index 252843f0..d9e4ef32 100644 --- a/test/05-device-state.spec.coffee +++ b/test/05-device-state.spec.coffee @@ -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': {