From 0e29e5f6f74694cd94ff1651ada7de3635f9b405 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Mon, 16 Jul 2018 17:48:03 +0100 Subject: [PATCH 1/3] Refactor config code to be consistent in location Change-type: patch Signed-off-by: Cameron Diver --- src/{lib/config-backend.ts => config/backend.ts} | 4 ++-- src/{lib/config-utils.ts => config/utils.ts} | 4 ++-- src/device-config.coffee | 2 +- test/05-device-state.spec.coffee | 2 +- test/13-device-config.spec.coffee | 2 +- ...6-config-utils.spec.coffee => 17-config-utils.spec.coffee} | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/{lib/config-backend.ts => config/backend.ts} (99%) rename src/{lib/config-utils.ts => config/utils.ts} (95%) rename test/{16-config-utils.spec.coffee => 17-config-utils.spec.coffee} (96%) diff --git a/src/lib/config-backend.ts b/src/config/backend.ts similarity index 99% rename from src/lib/config-backend.ts rename to src/config/backend.ts index 175235b6..2a79be4d 100644 --- a/src/lib/config-backend.ts +++ b/src/config/backend.ts @@ -3,8 +3,8 @@ import * as childProcessSync from 'child_process'; import * as _ from 'lodash'; import { fs } from 'mz'; -import * as constants from './constants'; -import * as fsUtils from './fs-utils'; +import * as constants from '../lib/constants'; +import * as fsUtils from '../lib/fs-utils'; const childProcess: any = Promise.promisifyAll(childProcessSync); diff --git a/src/lib/config-utils.ts b/src/config/utils.ts similarity index 95% rename from src/lib/config-utils.ts rename to src/config/utils.ts index 1497a8be..da1fd144 100644 --- a/src/lib/config-utils.ts +++ b/src/config/utils.ts @@ -1,12 +1,12 @@ import * as _ from 'lodash'; +import { EnvVarObject } from '../lib/types'; import { ConfigOptions, DeviceConfigBackend, ExtlinuxConfigBackend, RPiConfigBackend, -} from './config-backend'; -import { EnvVarObject } from './types'; +} from './backend'; const configBackends = [ diff --git a/src/device-config.coffee b/src/device-config.coffee index 8cdb0c2a..08370b06 100644 --- a/src/device-config.coffee +++ b/src/device-config.coffee @@ -4,7 +4,7 @@ _ = require 'lodash' systemd = require './lib/systemd' { checkTruthy, checkInt } = require './lib/validation' { UnitNotLoadedError } = require './lib/errors' -configUtils = require './lib/config-utils' +configUtils = require './config/utils' vpnServiceName = 'openvpn-resin' diff --git a/test/05-device-state.spec.coffee b/test/05-device-state.spec.coffee index 427278d6..252843f0 100644 --- a/test/05-device-state.spec.coffee +++ b/test/05-device-state.spec.coffee @@ -9,7 +9,7 @@ prepare = require './lib/prepare' DeviceState = require '../src/device-state' DB = require('../src/db') Config = require('../src/config') -{ RPiConfigBackend } = require('../src/lib/config-backend') +{ RPiConfigBackend } = require('../src/config/backend') Service = require '../src/compose/service' diff --git a/test/13-device-config.spec.coffee b/test/13-device-config.spec.coffee index 0de8924c..ee856b89 100644 --- a/test/13-device-config.spec.coffee +++ b/test/13-device-config.spec.coffee @@ -9,7 +9,7 @@ prepare = require './lib/prepare' fsUtils = require '../src/lib/fs-utils' DeviceConfig = require '../src/device-config' -{ ExtlinuxConfigBackend, RPiConfigBackend } = require '../src/lib/config-backend' +{ ExtlinuxConfigBackend, RPiConfigBackend } = require '../src/config/backend' extlinuxBackend = new ExtlinuxConfigBackend() rpiConfigBackend = new RPiConfigBackend() diff --git a/test/16-config-utils.spec.coffee b/test/17-config-utils.spec.coffee similarity index 96% rename from test/16-config-utils.spec.coffee rename to test/17-config-utils.spec.coffee index 99fca614..3c7a88a8 100644 --- a/test/16-config-utils.spec.coffee +++ b/test/17-config-utils.spec.coffee @@ -4,8 +4,8 @@ m = require 'mochainon' { fs } = require 'mz' -configUtils = require '../src/lib/config-utils' -{ ExtlinuxConfigBackend, RPiConfigBackend } = require '../src/lib/config-backend' +configUtils = require '../src/config/utils' +{ ExtlinuxConfigBackend, RPiConfigBackend } = require '../src/config/backend' extlinuxBackend = new ExtlinuxConfigBackend() rpiBackend = new RPiConfigBackend() From 1604fdf2761f17ef641d42040d97a0b91c5abb4f Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Tue, 17 Jul 2018 12:21:27 +0100 Subject: [PATCH 2/3] Allow the enabling and disabling of persistent logging via env var Closes: #698 Change-type: minor Signed-off-by: Cameron Diver --- src/config.ts | 1 + src/device-config.coffee | 31 ++++++++++++++++++++++++------- test/05-device-state.spec.coffee | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) 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': { From d9eee69fcd0c770a696303cc75d3ca346757d3a7 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Tue, 17 Jul 2018 20:40:33 +0000 Subject: [PATCH 3/3] v7.15.0 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f5ebe8..f023658f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v7.15.0 - 2018-07-17 + +* Allow the enabling and disabling of persistent logging via env var #700 [Cameron Diver] +* Refactor config code to be consistent in location #700 [Cameron Diver] + ## v7.14.1 - 2018-07-16 * Re-enable majority of tests #699 [Cameron Diver] diff --git a/package.json b/package.json index 9eb563fd..40796ec6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "resin-supervisor", "description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.", - "version": "7.14.1", + "version": "7.15.0", "license": "Apache-2.0", "repository": { "type": "git",