Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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) {
Expand Down Expand Up @@ -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
};
2 changes: 1 addition & 1 deletion src/cli/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cli/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 33 additions & 0 deletions src/config/constants.js
Original file line number Diff line number Diff line change
@@ -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',
}
3 changes: 2 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

const nconf = require('nconf')
const path = require('path')
const constants = require('./constants');

class Config {
constructor() {
Expand All @@ -22,7 +23,7 @@ class Config {
}

get(key) {
return nconf.get(key)
return nconf.get(key) || constants[key]
}

set(key, value) {
Expand Down
35 changes: 32 additions & 3 deletions src/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down