From 601c5d66d3abe939009706669a0badf70cc03b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88ran=20Sander?= Date: Wed, 5 Jan 2022 22:19:25 +0100 Subject: [PATCH 1/3] fix: Improved config robustness Fixes #134. Now more tolerant to missing values in config file. --- index.js | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 28171cb..c85e7a9 100644 --- a/index.js +++ b/index.js @@ -172,7 +172,10 @@ async function loadAppIntoCache(appConfig) { // const sched = later.parse.text(appConfig.freq); let nextRun; - if (globals.config.get('mqttConfig.out.tzFormat').toLowerCase() === 'local') { + if ( + globals.config.has('mqttConfig.out.tzFormat') && + globals.config.get('mqttConfig.out.tzFormat').toLowerCase() === 'local' + ) { // Use local timezone nextRun = nextOccurrences[1].toString(); } else { @@ -181,10 +184,15 @@ async function loadAppIntoCache(appConfig) { // eslint-disable-next-line no-param-reassign appConfig.nextRun = nextRun; - mqttClient.publish( - globals.config.get('mqttConfig.out.baseTopic'), - JSON.stringify(appConfig) - ); + if ( + globals.config.has('mqttConfig.out.enable') && + globals.config.get('mqttConfig.out.enable') === true + ) { + mqttClient.publish( + globals.config.get('mqttConfig.out.baseTopic'), + JSON.stringify(appConfig) + ); + } }); } else { app.session.close(); @@ -279,7 +287,10 @@ async function mainScript() { : null; // Start Docker healthcheck REST server on port set in config file - if (globals.config.get('dockerHealthCheck.enabled') === true) { + if ( + globals.config.has('dockerHealthCheck.enabled') && + globals.config.get('dockerHealthCheck.enabled') === true + ) { try { globals.logger.verbose('MAIN: Starting Docker healthcheck server...'); @@ -306,12 +317,18 @@ async function mainScript() { } // Set up heartbeats, if enabled in the config file - if (globals.config.get('heartbeat.enabled') === true) { + if ( + globals.config.has('heartbeat.enabled') && + globals.config.get('heartbeat.enabled') === true + ) { heartbeat.setupHeartbeatTimer(globals.config); } // Set up uptime logging - if (globals.config.get('uptimeMonitor.enabled') === true) { + if ( + globals.config.has('uptimeMonitor.enabled') && + globals.config.get('uptimeMonitor.enabled') === true + ) { serviceUptime.serviceUptimeStart(globals.config); } @@ -337,10 +354,16 @@ async function mainScript() { // Load cache warming config try { - if (globals.config.get('appConfig.configSource') === 'disk') { + if ( + globals.config.has('appConfig.configSource') && + globals.config.get('appConfig.configSource') === 'disk' + ) { appConfigYaml = fs.readFileSync(globals.config.get('appConfig.diskConfigFile'), 'utf8'); loadAppConfig(appConfigYaml); - } else if (globals.config.get('appConfig.configSource') === 'github') { + } else if ( + globals.config.has('appConfig.configSource') && + globals.config.get('appConfig.configSource') === 'github' + ) { const github = new GitHubApi({ // optional // debug: true, From 32a80c6794f70c5a8cdc7cd83fffb6c443c566c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88ran=20Sander?= Date: Wed, 5 Jan 2022 22:28:25 +0100 Subject: [PATCH 2/3] fix: Disable MQTT and uptime monitor in template config file Fixes #138 --- config/default_config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default_config.yaml b/config/default_config.yaml index c68f3c7..bc231af 100644 --- a/config/default_config.yaml +++ b/config/default_config.yaml @@ -37,7 +37,7 @@ dockerHealthCheck: # Uptime monitor # When enabled, Butler CW will write info on uptime and used memory to log files uptimeMonitor: - enabled: true # Should uptime messages be written to the console and log files? + enabled: false # Should uptime messages be written to the console and log files? frequency: every 60 seconds # https://breejs.github.io/later/parsers.html#text logLevel: verbose # Starting at what log level should uptime messages be shown? @@ -54,7 +54,7 @@ clientCertCAPath: /path/to/client/cert/root.pem # MQTT config parameters mqttConfig: out: - enable: true # Should info about cache run/warming events be sent as MQTT messages? + enable: false # Should info about cache run/warming events be sent as MQTT messages? baseTopic: butler-cw/ # Topic to send cache run events to. Should end with / tzFormat: UTC # LOCAL or UTC. Default is UTC broker: # MQTT server/broker config From 28780c487dd2c8eccf8e809e6d5f55eea99590bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88ran=20Sander?= Date: Wed, 5 Jan 2022 22:33:45 +0100 Subject: [PATCH 3/3] docs: Update sample config file in README --- README.md | 40 ++++++++++++++++++++++------------------ changelog.md | 12 ++++++++++++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 56db0be..b4df2ba 100644 --- a/README.md +++ b/README.md @@ -164,38 +164,43 @@ drwxr-xr-x 5 goran staff 160 Sep 27 10:43 .. -rw-r--r--@ 1 goran staff 1192 Sep 27 10:43 root.pem ``` -What do the config files look like? +What does a real-world config file look like? ```bash proton:butler-cw-docker goran$ cat config/production.yaml # Rename this file to production.yaml, and fill in data as needed below. # Logging configuration -logLevel: verbose # Log level. Possible log levels are silly, debug, verbose, info, warn, error -fileLogging: true # true/false to enable/disable logging to disk file +logLevel: info # Log level. Valid log levels are silly, debug, verbose, info, warn, error +fileLogging: true # true/false to enable/disable logging to disk file # Configuration of Butler CW's scheduler scheduler: startup: showPerAppSchedule: - enable: true # Should the first itemCount scheduled runs be shown for each app, on startup? - itemCount: 10 # Number of coming runs to show for each app + enable: true # Should the first itemCount scheduled runs be shown for each app, on startup? + itemCount: 10 # Number of coming runs to show for each app timeZone: # Valid values are UTC and LOCAL. Default value is UTC scheduleDefine: UTC # How should times in the apps config file be interpreted? - logs: UTC # What time format should be used in log files? + logs: UTC # What time format should be used in log files? + showNextEvent: + enable: true # Should date/time of next cache warming event be sent to log file? (true/false) + logLevel: warn # Log level to use for the next event log entry. Valid values are silly, debug, verbose, info, warn, error + tzFormat: UTC # LOCAL or UTC. Default is UTC -# Heartbeats can be used to send "I'm alive" messages to some other tool, e.g. an infrastructure monitoring tool -# The concept is simple: The remoteURL will be called at the specified frequency. The receiving tool will then know +# Heartbeats can be used to send "I'm alive" messages to any other tool, e.g. a infrastructure monitoring tool +# The concept is simple: The remoteURL will be called at the specified frequency. The receiving tool will then know # that Butler CW is alive. heartbeat: enabled: true - remoteURL: http://healthcheck.ptarmiganlabs.net/ping/138514b0-882a-4a44-8548-96f7d16c9242 - frequency: every 30 seconds # https://bunkat.github.io/later/parsers.html + remoteURL: https://healthcheck.ptarmiganlabs.net/ping/138514b0-882a-4a44-8548-96f7d16c9242 + # frequency: every 1 minute # https://bunkat.github.io/later/parsers.html + frequency: every 10 seconds # https://bunkat.github.io/later/parsers.html -# Docker health checks are used when running Butler CW as a Docker container. +# Docker health checks are used when running Butler CW as a Docker container. # The Docker engine will call the container's health check REST endpoint with a set interval to determine # whether the container is alive/well or not. -# If you are not running Butler CW in Docker you can safely disable this feature. +# If you are not running Butler CW in Docker you can safely disable this feature. dockerHealthCheck: enabled: true # Control whether a REST endpoint will be set up to serve Docker health check messages port: 12398 # Port the Docker health check service runs on (if enabled) @@ -204,7 +209,7 @@ dockerHealthCheck: # When enabled, Butler CW will write info on uptime and used memory to log files uptimeMonitor: enabled: true # Should uptime messages be written to the console and log files? - frequency: every 60 seconds # https://bunkat.github.io/later/parsers.html + frequency: every 10 seconds # https://bunkat.github.io/later/parsers.html logLevel: verbose # Starting at what log level should uptime messages be shown? # Paths to client certificates to use when connecting to Sense server. Can be pem or pvk/cer @@ -218,10 +223,9 @@ mqttConfig: out: enable: true # Should info about cache run/warming events be sent as MQTT messages? baseTopic: butler-cw/ # Topic to send cache run events to. Should end with / - tzFormat: UTC # LOCAL or UTC. Default is UTC - # Items below are mandatory if mqttConfig.enable=true - broker: - uri: mqtt://1.2.3.4:1883 ## Port is usually 1883 + tzFormat: UTC # LOCAL or UTC. Default is UTC + broker: # MQTT server/broker config + uri: mqtt://1.2.3.4:1883 ## Port is usually 1883 # QIX version to use qixVersion: 12.170.2 @@ -230,7 +234,7 @@ qixVersion: 12.170.2 appConfig: # Valid options are disk, github configSource: disk - + # Leave strings empty if disk config not used diskConfigFile: ./config/apps.yaml diff --git a/changelog.md b/changelog.md index a28b14a..02e8f64 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,17 @@ # Changelog +### [4.0.2](https://www.github.com/ptarmiganlabs/butler-cw/compare/butler-cw-v4.0.1...butler-cw-v4.0.2) (2021-12-01) + + +### Bug Fixes + +* Slim down release ZIP artefacts ([742c180](https://www.github.com/ptarmiganlabs/butler-cw/commit/742c1805e4d2eb15293a7ef9ffc8de24af6d1d70)) + + +### Miscellaneous + +* **deps:** Update dependencies ([5b75ad2](https://www.github.com/ptarmiganlabs/butler-cw/commit/5b75ad2f9732e64ad66655fb8a9450dd9b5f3d38)) + ### [4.0.1](https://www.github.com/ptarmiganlabs/butler-cw/compare/butler-cw-v4.0.0...butler-cw-v4.0.1) (2021-10-26)