From fbc23ae4903c9a92f66f7f8639c07610572e9f3a Mon Sep 17 00:00:00 2001 From: alexandershpak <35569337+alexandershpak@users.noreply.github.com> Date: Wed, 20 Feb 2019 15:03:44 +0300 Subject: [PATCH 1/4] bug(fix): Change order of controller's log files (ENG-584) --- src/logger/index.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/logger/index.js b/src/logger/index.js index 3be3f1e8d..2432fd2f3 100644 --- a/src/logger/index.js +++ b/src/logger/index.js @@ -13,9 +13,20 @@ const winston = require('winston'); const config = require('../config'); - +const fs = require('fs'); const MESSAGE = Symbol.for('message'); +const dirname = config.get('Service:LogsDirectory') + +// Create the log directory if it does not exist +try { + if (!fs.existsSync(dirname)) { + fs.mkdirSync(dirname); + } +} catch (e) { + // can't initialize log folder +} + const levels = { error: 0, warn: 1, @@ -67,13 +78,31 @@ const logger = winston.createLogger({ prepareObjectLogs(), formattedJson() ), - filename: 'iofog-controller.log', - dirname: config.get('Service:LogsDirectory'), + filename: 'iofog-controller.0.log', + dirname: dirname, maxsize: config.get('Service:LogsFileSize'), + rotationFormat: function() { + return getFormattedLogName(); + } }), ], }); +// logFileName pattern similar to agent +function getFormattedLogName() { + if (fs.existsSync(dirname)) { + fs.readdirSync(dirname).reverse().forEach(file => { + const path = dirname + '/' + file + if (fs.existsSync(path)) { + const strNumber = file.replace('iofog-controller.', '').replace('.log', '') + const number = parseInt(strNumber) + 1 + fs.renameSync(path, path.replace(strNumber, number)) + } + }); + } + return '' +} + logger.add(new winston.transports.Console({ level: 'info', format: winston.format((log) => { From e03ef7a0edb98d181e2423a989f16a63da657673 Mon Sep 17 00:00:00 2001 From: MaksimChepelev Date: Wed, 20 Feb 2019 15:06:41 +0300 Subject: [PATCH 2/4] feat(cli): fix help (ENG-742) --- src/cli/connector.js | 2 +- src/cli/controller.js | 2 +- src/cli/diagnostics.js | 2 +- src/cli/flow.js | 2 +- src/cli/registry.js | 2 +- src/cli/tunnel.js | 2 +- src/cli/user.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cli/connector.js b/src/cli/connector.js index eaffda741..83b1f2dcd 100644 --- a/src/cli/connector.js +++ b/src/cli/connector.js @@ -101,7 +101,7 @@ class Connector extends BaseCLIHandler { break; case constants.CMD_HELP: default: - return this.help([constants.CMD_LIST]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); diff --git a/src/cli/controller.js b/src/cli/controller.js index 8793bb5ce..dda25a068 100644 --- a/src/cli/controller.js +++ b/src/cli/controller.js @@ -63,7 +63,7 @@ class Controller extends BaseCLIHandler { break; case constants.CMD_HELP: default: - return this.help([constants.CMD_LIST]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); diff --git a/src/cli/diagnostics.js b/src/cli/diagnostics.js index 04a6ab8fb..62b08001d 100644 --- a/src/cli/diagnostics.js +++ b/src/cli/diagnostics.js @@ -103,7 +103,7 @@ class Diagnostics extends BaseCLIHandler { break; case constants.CMD_HELP: default: - return this.help([constants.CMD_LIST]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); diff --git a/src/cli/flow.js b/src/cli/flow.js index f0918ac47..99bcfcbba 100644 --- a/src/cli/flow.js +++ b/src/cli/flow.js @@ -107,7 +107,7 @@ class Flow extends BaseCLIHandler { break; case constants.CMD_HELP: default: - return this.help([constants.CMD_LIST]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); diff --git a/src/cli/registry.js b/src/cli/registry.js index 51b0397a7..59ba006ab 100644 --- a/src/cli/registry.js +++ b/src/cli/registry.js @@ -111,7 +111,7 @@ class Registry extends BaseCLIHandler { break; case constants.CMD_HELP: default: - return this.help([constants.CMD_LIST]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); diff --git a/src/cli/tunnel.js b/src/cli/tunnel.js index 8c54cb0c0..cc24be082 100644 --- a/src/cli/tunnel.js +++ b/src/cli/tunnel.js @@ -91,7 +91,7 @@ class Tunnel extends BaseCLIHandler { await _executeCase(tunnelCommand, constants.CMD_LIST, _tunnelList, false); break; default: - return this.help([constants.CMD_HELP]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); diff --git a/src/cli/user.js b/src/cli/user.js index 8154cb8d7..d858c4f37 100644 --- a/src/cli/user.js +++ b/src/cli/user.js @@ -101,7 +101,7 @@ class User extends BaseCLIHandler { break; case constants.CMD_HELP: default: - return this.help([constants.CMD_LIST]) + return this.help([]) } } catch (error) { this.handleCLIError(error, args.argv); From f2277df4a7bc8307433c85d9e9d94c3f849579ed Mon Sep 17 00:00:00 2001 From: alexandershpak <35569337+alexandershpak@users.noreply.github.com> Date: Wed, 20 Feb 2019 16:06:15 +0300 Subject: [PATCH 3/4] bug(fix): Change order of controller's log files update postinstall script for version less 1.0.37 (ENG-584) (#548) --- scripts/postinstall.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 9d8c5c076..98e21ad49 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -15,6 +15,7 @@ const os = require('os'); const execSync = require('child_process').execSync; const fs = require('fs'); const semver = require('semver'); +const config = require('../src/config'); const currentVersion = require('../package').version; const {restoreDBs, restoreConfigs, INSTALLATION_VARIABLES_FILE} = require('./util'); @@ -41,6 +42,10 @@ function postinstall() { console.log('upgrading from version <= 1.0.30 :'); updateEncryptionMethod(); } + if (semver.satisfies(prevVersion, '<=1.0.37')) { + console.log('upgrading from version <= 1.0.37 :'); + updateLogName(); + } fs.unlinkSync(INSTALLATION_VARIABLES_FILE); } catch (e) { @@ -151,6 +156,24 @@ function updateEncryptionMethod() { updateEncryptionMethodForEmailService(prodConfig, decryptTextVer30); } +function updateLogName() { + console.log(' updating log name in '); + const dirname = config.get('Service:LogsDirectory') + + if (fs.existsSync(dirname)) { + fs.readdirSync(dirname).forEach(file => { + const path = dirname + '/' + file + if (fs.existsSync(path)) { + fs.unlinkSync(path, function(err) { + if (err) return console.log(err); + console.log('log deleted successfully'); + }) + } + }); + } + +} + module.exports = { postinstall: postinstall }; \ No newline at end of file From 705a2afe1239219b3f380dbdbc5546cd1af619c3 Mon Sep 17 00:00:00 2001 From: MaksimChepelev Date: Wed, 20 Feb 2019 16:08:07 +0300 Subject: [PATCH 4/4] feat(config): add default config values in js code (#549) * feat(config): add dafault config values in js code increase stability. this allow to work without any config fix memory leack problem in jobs Closes ENG-630 * feat(config): add dafault config values in js code fix formatting Closes ENG-630 * 9!!! --- src/config/constants.js | 33 +++++++++++++++++++++++++++++++++ src/config/index.js | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/config/constants.js diff --git a/src/config/constants.js b/src/config/constants.js new file mode 100644 index 000000000..21dc6e958 --- /dev/null +++ b/src/config/constants.js @@ -0,0 +1,33 @@ +/* + * ******************************************************************************* + * * Copyright (c) 2019 Edgeworx, Inc. + * * + * * This program and the accompanying materials are made available under the + * * terms of the Eclipse Public License v. 2.0 which is available at + * * http://www.eclipse.org/legal/epl-2.0 + * * + * * SPDX-License-Identifier: EPL-2.0 + * ******************************************************************************* + * + */ + +module.exports = { + 'App:Name': 'iofog-controller', + + 'Server:Port': 54421, + 'Server:DevMode': false, + + 'Email:ActivationEnabled': false, + 'Email:HomeUrl': 'https://iofog.org', + + 'Service:LogsDirectory': '/var/log/iofog-controller', + 'Service:LogsFileSize': 1048576, + + 'Settings:DefaultJobIntervalSeconds': 120, + 'Settings:UserTokenExpirationIntervalSeconds': 3600, + 'Settings:FogTokenExpirationIntervalSeconds': 3600, + 'Settings:FogStatusUpdateIntervalSeconds': 120, + 'Settings:FogStatusFrequencySeconds': 60, + + 'Diagnostics:DiagnosticDir': 'diagnostic', +} \ No newline at end of file diff --git a/src/config/index.js b/src/config/index.js index 8b10ec58d..bc5897449 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -13,6 +13,7 @@ const nconf = require('nconf') const path = require('path') +const constants = require('./constants'); class Config { constructor() { @@ -22,7 +23,7 @@ class Config { } get(key) { - return nconf.get(key) + return nconf.get(key) || constants[key] } set(key, value) {